0

目前我正在使用它来检查/取消选中我表单中的所有复选框。

<script type="text/javascript">
checked=false;
function checkedAll (frm1) {
    var aa= document.getElementById('frm1');
     if (checked == false)
          {
           checked = true
          }
        else
          {
          checked = false
          }
    for (var i =0; i < aa.elements.length -2; i++) 
    {
     aa.elements[i].checked = checked;
    }
      }
</script>

这很好用,但我不想受到影响,但我在此表单中有一个复选框。

它有一个 id id='ignore'无论如何上面的代码可以用来工作,但忽略这个复选框?

谢谢

4

5 回答 5

2
for (var i =0; i < aa.elements.length -2; i++) 
    {
        if(aa.elements[i].id !== 'ignore'){
             aa.elements[i].checked = checked;
         }
    }
于 2013-02-07T10:50:04.643 回答
1

摆脱 if 循环也......
完整的代码 -

<script type="text/javascript">

var checked = false;

function checkedAll (frm1) {
    var chkBoxs = document.getElementById('frm1').getElementsByTagName('input');

    checked = !checked;

    for (var i =0; i < chkBoxs.length -2; i++) {
        if (chkBoxs[i].id == 'ignore') {
            continue;
        }
        chkBxs[i].checked = checked;
    }
}

</script>
于 2013-02-07T11:02:59.940 回答
0
for (var i =0; i < aa.elements.length -2; i++) 
{
if (aa.elements[i].getAttribute('id') != 'ignore')
 aa.elements[i].checked = checked;
}
于 2013-02-07T10:51:04.987 回答
0
for (var i =0; i < aa.elements.length -2; i++) 
{
if (aa.elements[i].getAttribute('id') == 'ignore') 
continue;
 aa.elements[i].checked = checked;
}
于 2013-02-07T10:51:58.787 回答
0
<script type="text/javascript">
checked=false;
function checkedAll (frm1) {
    var aa= document.getElementById('frm1');
     if (checked == false)
          {
           checked = true
          }
        else
          {
          checked = false
          }
     for (var i =0; i < aa.elements.length -2; i++) 
       {
         if (aa.elements[i].getAttribute('id') == 'ignore') 
             aa.elements[i].checked = false;
         else
             aa.elements[i].checked = checked;
     }
      }
</script>
于 2013-02-07T10:54:35.923 回答