代码

//设置选中 
$('#check1').prop('checked', true);

//是否选中 
var isChecked = $('#cb').prop('checked');
//或 
var isChecked = $('#cb').is(":checked");

var isChecked = $('#cb').attr('checked');

 

代码

function publish()
    {
        var a = $("#check1").prop('checked');
        var b = $("#check2").prop('checked');
        console.log(a);
        console.log(b);
       if ($("#check1").attr('checked') && $("#check2").attr('checked'))
           window.location.href = "{:url('index/article/addArticle')}";
        else{
           alert('请全部勾选');
           return false;
       }
    }

执行结果

JavaScript复选框是否选中判断_js判断选中