开发者

Forwarding to Anchor Tag After Using select

开发者 https://www.devze.com 2023-01-26 09:55 出处:网络
I\'ve got a select list and I want people to be directed to id tags once they choose their respective options.

I've got a select list and I want people to be directed to id tags once they choose their respective options.

Forwarding to Anchor Tag After Using select

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消