jQuery更改功能在Safari浏览器中不起作用 [英] JQuery change function not working in safari browser
本文介绍了jQuery更改功能在Safari浏览器中不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个单选按钮和一个复选框
I have a radio button and checkbox
<input type='radio' name='testradiochange' id='testradiochange'> Testing Radio Change</input>
<input type='checkbox' name='acknowledge' id='acknowledge' value='acknowledge'></input>
我希望在选择这些按钮时收到通知
I want to be notified when these buttons are selected
$("input[name=testradiochange]:radio").change(function () {
alert('radio selected');
}
$("input[name=acknowledge]:checkbox").change(function () {
alert('checkbox selected');
}
以上内容在Chrome和Firefox中可以正常运行,但在Safari中则不能.任何的想法?
The above works fine in Chrome and Firefox but not in Safari. Any idea?
推荐答案
您的代码中有很多错别字,如下:
You have lots of typos in your code, here are they:
$("input[name=testradiochange]:radio").change(function () {
alert('radio selected');
}); // <= it was just }, i added ); to close the function's (
$("input[name=acknowledge]:checkbox").change(function () {
if ($(this).is(':checked')) { // if check
alert('checkbox selected');
} else { // if uncheck
alert('checkbox unselected');
}
}); // <= it was just }, i added ); to close the function's (
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<label><input type='radio' name='testradiochange' id='testradiochange'/>Testing Radio Change</label>
<!-- inputs don't have closing tags, they are self-closing, if you want to display text next to them, use a label -->
<input type='checkbox' name='acknowledge' id='acknowledge' value='acknowledge'/>
这篇关于jQuery更改功能在Safari浏览器中不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文