我正在尝试使用选项标签锚定一个 div,但它不起作用,我的代码有什么问题?这是锚片段
<select>
<option value="#b1">1 test</option>
</select>
<br />
<br />
<br />
<br />
<br />
<br />
<div id="b1">Testing!</div>
请参阅HTML 中的导航下拉菜单 (尤其是关于它们如何可怕的部分,您应该使用一组正常的链接)
尝试这样的事情:
<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()