Forwarding to Anchor Tag After Using select
I've got a select list and I want people to be directed to id tags once they choose their respective options.
I know that I'm going to have to use some kind of onClick() but what is the Java开发者_如何学CScript that I should use to forward to the anchor of the value?
See this answer: Programmatically scroll to an Anchor Tag
Basically...
onclick="document.getElementById('targetID').scrollIntoView(true);"
or
window.location.href = '#targetName';
However, it looks like at least some versions of IE don't recognize clicks on <options>
, so you'll have to place the onclick code on the <select>
instead. If you make the value of each option the #anchor you're going to (and remember, set the id of the anchors as well as the name), you should be able to get the value of the clicked option and then scroll to it. This will take a lot less code as well since you write one scrolling function in one click event, and then maintain the data of the option values.
精彩评论