javascript onclick警报在chrome中不起作用 [英] javascript onclick alert not working in chrome

查看:30
本文介绍了javascript onclick警报在chrome中不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

<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>

有人可以帮我写这个脚本吗?我期待每当用户点击历史 1 ..它会提醒 h1该脚本适用于 firefox 和 IE,但不适用于 Chrome :(

could someone help me with this script? i am expecting that whenever the user clicks history 1 ..it will alert h1 the script works in firefox and IE but not in Chrome :(

推荐答案

选择列表使用 onchange 而不是 onclick.

use onchange instead of onclick for select lists.

<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>

这篇关于javascript onclick警报在chrome中不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆