How to anchor with <option> tag in HTML?
I'm trying to anchor a div with an option tag but it doesn't work, what´s wron开发者_如何学编程g with my code? Here´s the anchor snippet
<select>
<option value="#b1">1 test</option>
</select>
<br />
<br />
<br />
<br />
<br />
<br />
<div id="b1">Testing!</div>
Try something like this:
FIDDLE
<select onchange="location = this.options[this.selectedIndex].value;">
<option value="#b1">1 test</option>
<option value="#b2">2 test</option>
<option value="#b3">3 test</option>
</select>
<div id="b1">Testing 1</div>
...
<div id="b2">Testing 2</div>
...
<div id="b3">Testing 3</div>
...
You'll need to add an onchange handler to the select element.
function scrollTo(elmt) { $(elmt.options[elmt.selectedIndex].value).scrollTo(); //With Prototype }
To your select, add onchange=scrollTo()
精彩评论