我有这个脚本
$('[data-toggle="wizard-checkbox"]').click(function(){
if( $(this).hasClass('active')){
$(this).removeClass('active');
$(this).find('[type="checkbox"]').removeAttr('checked');
} else {
$(this).addClass('active');
$(this).find('[type="checkbox"]').attr('checked','true');
}
});
他添加了 checked="checked"但单选框或复选框仍然是 未检查并且请求:Laravel 中的所有内容都看不到这个。如何编辑此以执行此检查?
最佳答案
您想使用 .prop()
。
// Check all checkboxes found
jQuery('[type="checkbox"]').prop( "checked", true );
// Uncheck all checkboxes found
jQuery('[type="checkbox"]').prop( "checked", false );
有关更多详细信息,请阅读 jQuery docs on .prop()
关于javascript - 如何对checkbox、radio做checked? Javascript,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42449621/