表单元素的checked、selected或disabled状态,用attr()方法,没法获得想要的布尔值(true/false)。html
<!-- 下面是标准定义,也能够直接写checked/disabled/selected -->
<input type="checkbox" checked="checked" id="checkboxInput">
<input type="text" disabled="disabled" id="textInput">
<select>
<option>001</option>
<option selected="selected" id="second">002</option>
</select>
<script>
$('#checkboxInput').attr('checked')//返回 checked
$('#checkboxInput').prop('checked')//返回 true
$('#textInput').attr('disabled')//返回 disabled
$('#textInput').prop('disabled')//返回 true
$('#second').attr('selected')//返回 selected
$('#second').prop('selected')//返回 true
</script>
复制代码
用做判断条件时:segmentfault
if (elem.checked)
if ($(elem).prop("checked"))
if ($(elem).is(":checked"))
复制代码
参考连接浏览器