- <script language=javascript>
- //第一种方法
- function selectall1()
- {
- var a = document.getElementsByTagName("input");
- if(a[0].checked==true){
- for (var i=0; i<a.length; i++) <="" span="">
- if (a[i].type == "checkbox") a[i].checked = false;
- }
- else
- {
- for (var i=0; i<a.length; i++) <="" span="">
- if (a[i].type == "checkbox") a[i].checked = true;
- }
- }
- //第二种方法
- function selectall2() {
- var tform = document.forms['form1'];
- for (var i=0;i<tform.length;i++) <="" span="">
- {
- var e = tform.elements[i];
- if (e.type == "checkbox")
- e.checked = !e.checked;
- }
- }
- //第三种方法,结合上述两种方法
- function selectall3()
- {
- var a = document.getElementsByTagName("input");
- for (var i=0; i<a.length; i++) <="" span="">
- if (a[i].type == "checkbox") a[i].checked =!a[i].checked;
- }
- //第四种方法
- function selectall4(id){ //用id区分
- var tform=document.forms['form1'];
- for(var i=0;i<tform.length;i++){ <="" span="">
- var e=tform.elements[i];
- if(e.type=="checkbox" && e.>}
- }
- //第五种方法
- function selectall(theform,thename){ //theform指定的form,thename是checkbox的name属性
- var tform=document.forms[theform];
- document.getElementById("thewen").value='反选';
- for(var i=0;i<tform.length;i++){ <="" span="">
- var e=tform.elements[i];
- if(e.type=='checkbox' && e.> }
- }
- </script>
javascript控制多选复选框
最新推荐文章于 2023-10-09 15:26:33 发布