Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/68.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Jquery 将复选框设为未选中_Jquery - Fatal编程技术网

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);
        }

    });

});