標籤:
javascript實現全選,反選及全部選
html 代碼:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=gb2312" /><title>無標題文檔</title><script language="javascript">function select1(oper){var arr= document.getElementsByName("fav");for(var i=0;i<arr.length;i++){switch(oper){case 1:arr[i].checked=oper;break;case 0:arr[i].checked=oper;break;case -1:arr[i].checked=! arr[i].checked;break;}}}</script></head><body><input type="checkbox" name="fav" value="吃飯"/>吃放<input type="checkbox" name="fav" value="吃飯2"/>吃放2<input type="checkbox" name="fav" value="吃飯3"/>吃放3<input type="checkbox" name="fav" value="吃飯4"/>吃放5<input type="checkbox" name="fav" value="吃飯6"/>吃放6<input type="checkbox" name="fav" value="吃飯7"/>吃放7<input type="checkbox" name="fav" value="吃飯8"/>吃放8<input type="button" value="全選" onclick="select1(1)" /><input type="button" value="反選" onclick="select1(-1)" /><input type="button" value="取消" onclick="select1(0)" /></body></html>
javascript實現全選,反選及全不選(其一)