javascript onclick警报在chrome中不起作用

编程入门 行业动态 更新时间:2024-10-09 20:29:43
本文介绍了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="ajax.googleapis/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中不起作用

本文发布于:2023-11-27 21:22:44,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1639651.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:警报   中不   javascript   onclick   chrome

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!