checkbox:
默认选中
<input id="checkbox1" type="checkbox" checked="checked" /><input id="radio1" type="radio" checked="checked" />
当我们想让checkbox或者radio默认选中时,只要设置了checked属性,不管该属性的值是什么,都会默认选中。
默认不可选中(不可点击)
<input id="checkbox2" type="checkbox" disabled="disabled" /><input id="radio2" type="radio" disabled="disabled" />
与默认选中一样,当我们想让checkbox或者radio不可点击时,只要设置了disabled属性,不管该属性的值是什么,都是不可选中的。
动态修改checkbox或者radio选中状态和不可选中状态
// 设置checked属性为true,就是选中状态$('#checkbox1').prop('checked', true);// 设置checked属性为false,就是不选中状态$('#checkbox1').prop('checked', true);// 设置disabled属性为true,就是不可选中状态$('#checkbox1').prop('disabled', true);// 设置disabled属性为false,就是可选中状态$('#checkbox1').prop('disabled', false);