mmt*_*mmt 6 checkbox jquery checked
我想根据checkbox click/unclick事件设置一个变量(pageselected).
<thead>
<tr id="othercheckbox">
<th width="10"><input type="checkbox" name="zip" class="all" value="all" /></th>
</tr>
</thead>
Run Code Online (Sandbox Code Playgroud)
$('#othercheckbox').click(function() {
if($(this).is(':checked')){
console.log("CCCCheckeddddddd");
that.pageselected = true;
}
else
{
console.log("UNCheckeddddddd");
that.pageselected = false;
}
}
Run Code Online (Sandbox Code Playgroud)
但这并不像预期的那样.我哪里错了?
Shi*_*tal 12
您正在检查行是否已选中,这是不可能onchange的.复选框上的绑定事件.把它放在复选框上,让我们说复选框1.
<input type="checkbox" name="zip" id="checkbox1" class="all" value="all" />
Run Code Online (Sandbox Code Playgroud)
$('#checkbox1').change(function(){
if($(this).is(':checked')){
console.log("CCCCheckeddddddd");
}
else
{
console.log("UNCheckeddddddd");
}
});
Run Code Online (Sandbox Code Playgroud)
由于复选框位于tr带有id的位置othercheckbox..使用此选项
$('#othercheckbox input[name="zip"]').click(function () {
if ($(this).is(':checked')) {
alert("CCCCheckeddddddd");
//that.pageselected = true;
} else {
alert("UNCheckeddddddd");
//that.pageselected = false;
}
});
Run Code Online (Sandbox Code Playgroud)