<select class="input" style="width:200px">
<option>---</option>
<option onclick="window.location="link.php">one</option>
<option onclick="window.location="link2.p开发者_运维百科hp"">two</option>
</select>
It doesn't work in chrome, it work in opera/mozilla and so on. Any advice?
<select class="input" onchange="window.location.href = this.value" style="width:200px">
<option>---</option>
<option value="link.php">one</option>
<option value="link2.php">two</option>
</select>
I know its not EXACTLY the same... but having a click event on the option of a select list is not good practice. Instead of onchange, you could have onclick as well... but onchange really is the way to do this, in my opinion.
Probably the safest approach is to use the onchange event of the select element, and use its value to determine the action to take. I don't think onclick works for option in IE, either.
Are the double quotes inside the onclick attributes not meant to be single quotes ?
The onclick isn't going to work the way you're trying to get it to work, and you're going to have to account for differences in how the browsers deal with the select
object. I would advise that you use the onchange event on the select
object, then test for the selected option. Note that these events fire differently on different browsers.
精彩评论