【问题标题】:JQuery change function not working in safari browserJQuery更改功能在Safari浏览器中不起作用
【发布时间】:2018-01-27 14:46:33
【问题描述】:

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

<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 中则不行。任何想法?

【问题讨论】:

  • 使用oninput 代替onchange?

标签: javascript jquery google-chrome safari


【解决方案1】:

你的代码中有很多错别字,这里是:

$("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 3.2.1 版。我尝试使用 2.1.1 但仍然没有用。有趣的是,当我在本地运行我的节点应用程序(jquery 中的 ui)时它可以工作,但是一旦它部署在服务器中,它就不起作用了。还在研究中
猜你喜欢
  • 2017-11-04
  • 2015-05-06
  • 1970-01-01
  • 2012-02-22
  • 2017-11-11
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多