怎样获取html控件checkbox是否以选中

html-css09

怎样获取html控件checkbox是否以选中,第1张

<input type="checkbox" id="checkbox1" />

<script>

$(document).ready(function(){

if($("#checkbox1").attr("checked")==true)

{

alert("checkbox已选中")

}

})

</script>

用jq来实现:

$('#select-all').click(function(event) {

if(this.checked) {

// Iterate each checkbox

$(':checkbox').each(function() {

this.checked = true

})

}})