问题描述
我认为我很愚蠢,但我似乎无法让我的onClick通过Chromium工作,这是Chrome的Linux版本(FireFox很好,和IE一样)
I think I'm being silly or something, but I can't seem to get my onClick to work through Chromium, which is a Linux version of Chrome (FireFox is fine, as is IE)
以下是一些HTML代码:
Here's some HTML code:
<form>
<select name="month">
<option value="1" onclick="javascript:window.location.href='<SOMEPAGE>'; return false;">January</option>
<option value="2">February</option>
<option value="3">March</option>
<option value="4">April</option>
<option value="5">May</option>
<option value="6">June</option>
<option value="7">July</option>
<option value="8">August</option>
<option value="9">September</option>
<option value="10">October</option>
<option value="11">November</option>
<option value="12">December</option>
</select>
</form>
推荐答案
我相信不支持在选项元素上使用onClick在所有浏览器上。即使这样做仍然可能有更好的方法。
I believe that using onClick on option elements is not supported on all browsers. Even if it is then there are still probably better ways of doing it.
如何使用select的onChange事件,然后检查选择哪个选项。然后添加其他选项的情况非常容易,而不会让html变得混乱。
How about using the onChange event of the select and then checking to see which option has been selected. It's then very easy to add cases for other options without your html getting messy.
例如
<form>
<script language="JavaScript">
function doSomething() {
selected=document.getElementById("month")[document.getElementById("month").selectedIndex].value;
switch(selected) {
case "1":
window.location.href='http://www.ibm.com';
break;
}
}
</script>
<select name="month" id="month" onChange="doSomething()">
<option value="1">January</option>
<option value="2">February</option>
<option value="3">March</option>
<option value="4">April</option>
<option value="5">May</option>
<option value="6">June</option>
<option value="7">July</option>
<option value="8">August</option>
<option value="9">September</option>
<option value="10">October</option>
<option value="11">November</option>
<option value="12">December</option>
</select>
</form>
这篇关于onClick Window.Location在Chromium中不起作用(Linux版Google Chrome)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!