kap*_*ffy 6 javascript select google-chrome onclick
<select name="history" id="history" >
<option value="history 1" onClick="alert('h1');">history 1</option>
<option value="history 2" onClick="alert('h2');">history 2</option>
<option value="clearhistory" onClick="this.form.submit();" >Clear History</option>
</select>
Run Code Online (Sandbox Code Playgroud)
有人可以帮我这个脚本吗?我希望每当用户点击历史记录1 ..它将警告h1脚本在firefox和IE中工作,但不在Chrome中:(
小智 12
如果要onClick
在Chrome,IE等中使用选项元素,则必须使用short fix:onChange
select元素的set 属性"this.options[this.selectedIndex].onclick()"
Sil*_*ter 10
使用onchange代替onclick选择列表.
<select name="history" id="history" onchange="historyChanged(this);">
<option value="history1">history 1</option>
<option value="history2">history 2</option>
<option value="clearhistory">Clear History</option>
</select>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.min.js"></script>
<script type="text/javascript">
function historyChanged() {
var historySelectList = $('select#history');
var selectedValue = $('option:selected', historySelectList).val();
alert(selectedValue);
if (selectedValue == 'clearHistory') {
historySelectList.form.submit();
}
}
$(function() {
alert('my alert');
$('select#history').change(historyChanged);
});
</script>
Run Code Online (Sandbox Code Playgroud)
在select而不是每个选项上使用onChange.这里是jsfiddle http://jsfiddle.net/tBjkg/
<select name="history" id="history" onChange="alert(this.value);">
<option value="history1">history 1</option>
<option value="history2">history 2</option>
<option value="clearhistory">Clear History</option>
</select>
Run Code Online (Sandbox Code Playgroud)
alert(this.value)指的是当前所选的select中的选项的值.
归档时间: |
|
查看次数: |
24997 次 |
最近记录: |