Jquery 将复选框设为未选中
我无法将选中的复选框改为未选中的复选框Jquery 将复选框设为未选中,jquery,Jquery,我无法将选中的复选框改为未选中的复选框 $("#search_list").find('.mselect input:checked').each(function(index, ele) { var prodId = $(this).val(); console.log($(this)); //if($(this).is(':checked')){ //if($(this).length) {
$("#search_list").find('.mselect input:checked').each(function(index, ele) {
var prodId = $(this).val();
console.log($(this));
//if($(this).is(':checked')){
//if($(this).length) {
$(productList).each(function(key, value) {
console.log("ohh"+value);
if(prodId == value){
$(this).prop('checked', false);
console.log($(this));
console.log("unchedk"+value);
}
});
//}
});
我的错误是什么?上下文$(此)
指的是产品列表的当前元素/属性。将复选框的$(this)
分配给变量,如(已删除注释代码)
您应该包括您试图更改的控件的HTML,以及在浏览器控制台中看到的任何错误消息。@Andreas,您完全正确。我想我学到的约定有一个缺陷。是的$这个不是指复选框。这是指productList的数组。是的,我理解我的错误。谢谢
$("#search_list").find('.mselect input:checked').each(function(index, ele) {
var $checkbox = $(this), // now use $checkbox instead of $(this) in the next loop
// (the dollar sign is to indicate that the variable is alreay a jQuery object).
prodId = $(this).val();
$(productList).each(function(key, value) {
if (prodId == value) {
$checkbox.prop('checked', false);
}
});
});