gpt4 book ai didi

javascript - JQuery 更改功能在 safari 浏览器中不起作用

转载 作者:行者123 更新时间:2023-11-28 17:50:00 26 4
gpt4 key购买 nike

我有一个单选按钮和复选框

<input type='radio' name='testradiochange' id='testradiochange'> Testing Radio Change</input>

<input type='checkbox' name='acknowledge' id='acknowledge' value='acknowledge'></input>

我希望在选择这些按钮时收到通知

$("input[name=testradiochange]:radio").change(function () {
alert('radio selected');
}

$("input[name=acknowledge]:checkbox").change(function () {
alert('checkbox selected');
}

上面的代码在 Chrome 和 Firefox 中运行良好,但在 Safari 中则不行。任何想法?

最佳答案

您的代码中有很多拼写错误,如下:

$("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'/>

关于javascript - JQuery 更改功能在 safari 浏览器中不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45764703/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com