在以下代碼中 - 如何執行檢查並取消選中。現在它只做一件事:On Off Switch - 複選框
$('#div_group').click(function() {
var status = $(this).attr('checked');
if(! status) {
status = false;
}
$("input[id~='div_group']").attr('checked', true);
});
在以下代碼中 - 如何執行檢查並取消選中。現在它只做一件事:On Off Switch - 複選框
$('#div_group').click(function() {
var status = $(this).attr('checked');
if(! status) {
status = false;
}
$("input[id~='div_group']").attr('checked', true);
});
使用.prop
而不是.attr
:
$('#div_group').click(function() {
var $this = $(this);
$("input[id~='div_group']").prop('checked', $this.is(':checked'));
});
你需要使用道具而不是attr。 嘗試...
$("input[id~='div_group']").prop('checked', true);
,然後取消選中它設置true
到false
謝謝。道具做了魔術。 – New2JQ