2012-05-04 93 views

回答

1
<div><input type="checkbox" class="checkall"> Check all</div> 
    <div><input type="checkbox" class="check"> Checkbox</div> 
    <div><input type="checkbox" class="check"> Checkbox</div> 
    <div><input type="checkbox" class="check"> Checkbox</div> 

    <select size="5" multiple="multiple" class="listbox"> 
     <option value="test1">test1</option> 
     <option value="test1">test1</option> 
     <option value="test1">test1</option> 
     <option value="test1">test1</option> 
     <option value="test1">test1</option> 
    </select> 


<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js" type="text/javascript"></script> 
<script> 
$(function() { // this line makes sure this code runs on page load 
    $('.checkall').click(function() { 
     $('.check').attr('checked', this.checked); //if you want to select/deselect checkboxes use this 
     $('.listbox option').attr('selected', this.checked);//if you want to select/deselect options in list use this 
    }); 
}); 
</script> 

http://jsfiddle.net/fMk2e/

3

.checked將返回你閹羊選擇或不比你可以選擇所有

e.g我已經採取了樣本例如

var idckbIsSolicitor = '<%= ckbIsSolicitor.ClientID %>'; 
var ckbIsSolicitor = document.getElementById(idckbIsSolicitor); 

if (ckbIsSolicitor.checked) 
{ 
//select all 
} 
else 
{ 
//deselect all 
} 
相關問題