Jquery根据选中的另一个复选框设置复选框

时间:2015-03-04 04:23:12

标签: jquery checkbox set

我检查第一个复选框时有两个复选框,第二个复选框应该选择简单方便!但我无法弄清楚错误是什么以及为什么在html编辑器中没有检查第二个复选框 还有一件事我的复选框的导出值为1,因此当选中时应为1

var opt_identity = $('#chkOpt_contractType').val();
var ShortSale = $('#chkOptShortSale').val();

if (opt_identity == 1) 
{   
    // I tried both of these lines but still i dont see the check box being check 
$('input[name="chkOptShortSale"][value='1']').prop('checked', true);
$('#chkOptShortSale').prop('checked', true);
} else {
$('.checked').removeAttr('checked');
alert('HH Else = ' + ShortSale); 

1 个答案:

答案 0 :(得分:0)

使用此

if (opt_identity == 1) {   
$('input[name="chkOptShortSale"][value="1"]')).prop(''checked'', true);
$('#chkOptShortSale').prop('checked', true);
} else {
$('.checked').removeAttr('checked');
alert('HH Else = ' + ShortSale); 
}
相关问题