简体   繁体   English

jQuery代码在Firefox上有效,但在Chrome和Opera中不可用

[英]Jquery Code works on Firefox but not in Chrome & Opera

I wonder this code does not trigger in Chrome. 我想知道这段代码不会在Chrome中触发。 It works as expected in FireFox. 它在FireFox中按预期工作。

 $("#filter-price :checkbox").on("click", function() { $("#product-results").empty(); }); 
 <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <ol class="items" id="filter-price"> <li class="item "> <label> <input type="checkbox" value="0-20"><span>$0 - $20 <span class="count"></span> </span> </label> </li> <li class="item "> <label> <input type="checkbox" value="20-50"><span>$20 - $50 <span class="count"></span> </span> </label> </li> </ol> 

Your JavaScript is executed before the html elements input:checkbox are available in Chrome/Opera. Chrome / Opera中的html元素input:checkbox可用之前,将执行JavaScript。

Wrap your JavaScript into a document.ready : 将您的JavaScript包装到document.ready中

$(function() {
    console.log('Register click event on:', $("#filter-price :checkbox"));
    $("#filter-price :checkbox").on("click", function() {
      console.log('Click event recognized', {checkbox: $(this) elToEmpty: $("#product-results")});
      $("#product-results").empty();
    });
});

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 jQuery代码可在Firefox,Opera中使用,但不能在Chrome和IE中使用 - JQuery Code works in Firefox, Opera but not working in Chrome and IE js 代码适用于 firefox 但不适用于 chrome 歌剧和边缘 - a js code works on firefox but not on chrome opera and edge jQuery代码可在Firefox和Opera中运行,但不能在Chrome和IE中运行-无法正确读取复选框值 - jQuery code works in Firefox and Opera,but not in Chrome and IE - not reading checkbox value correctly jQuery ajax调用WebApi可在IE上运行,但不能在Firefox,Chrome或Opera上运行 - jQuery ajax call to WebApi works on IE but not Firefox, Chrome or Opera jQuery在Internet Explorer 9中无法使用(但在Firefox,Chrome和Opera中可以使用) - jQuery not working in Internet Explorer 9 (but works in Firefox, Chrome and Opera) 带load()的jquery-issue:适用于Firefox和Safari,不适用于Chrome,Opera和IE - jquery-issue with load(): works with Firefox and Safari, not with Chrome, Opera and IE Firefox和Chrome,Opera上的jQuery Ajax问题(在Safari上运行良好) - jQuery Ajax problems on Firefox and Chrome, Opera (works well on Safari) jQuery 脚本在 Chrome 中有效,但在 FireFox 和 Opera 中无效 - jQuery script which works in Chrome, but does not work in FireFox and Opera jQuery .css()在IE 6,7,8和Firefox中不起作用,但在Chrome,Safari,Opera中起作用 - jQuery .css() not working in IE 6,7,8 and Firefox, but works in Chrome, Safari, Opera jQuery代码适用于Firefox,但不适用于Chrome - jQuery code works in Firefox but not in Chrome
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM