我是jquery的新手,我不知道如何使用它,这是我创建的代码看起来像
<div id="checkbox-container">
<div class="hidefull">
<input type="checkbox" value="hideFull" id="check-hide-full-table">Hide Full
</div>
<div class="hideempty">
<input type="checkbox" value="hideEmpty" id="check-hide-empty-table">Hide Empty
</div>
</div>
和jquery我这样创建
function test(){
alert("test called");
$("#check-hide-empty-table").prop("checked", true);
}
所以问题是,如何使用jquery检查复选框?我已经看了this但仍未查看。有人知道我的代码有什么问题吗?
我想创建如果加载新页面,那个复选框,选中。
仅供参考,该警报显示。
答案 0 :(得分:0)
jQuery(document).ready(function() {
test("#check-hide-empty-table");
});
function test(input){
alert("test called");
testInput = jQuery(input);
testInput.click(function(){
if(this.checked != true) {
alert('not checked');
return false;
}
alert('checked');
return true;
});
}
答案 1 :(得分:-1)
以下是解决方案:Demo
$(document).ready(function() {
$('input').on('change', function() {
if ($(this).attr("checked")) {
$(this).attr("checked", false);
} else {
$(this).attr("checked", true);
}
});
});
选中复选框后,它会添加已检查的属性,如果未选中,则会取出检查