我想知道此代码不会在Chrome中触发。它在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>
&#13;
答案 0 :(得分:0)
您的JavaScript是在Chrome / Opera中提供html元素input:checkbox
之前执行的。
将您的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();
});
});