毕业论文开发语言企业开发JAVA技术.NET技术WEB开发Linux/Unix数据库技术Windows平台移动平台嵌入式论文范文英语论文
您现在的位置: 毕业论文 >> windows平台 >> 正文

checkbox点中后自动选中此类别下子选项checkbox的问题

更新时间:2013-4-10:  来源:毕业论文

checkbox点中后自动选中此类别下子选项checkbox的问题
<table> <tr id="node-1">    <td>总类一</td>    <td><input class="inputcheckbox" type="checkbox" name="ids[1][1]"/>&nbsp;选项1    <td><input class="inputcheckbox" type="checkbox" name="ids[1][2]"/>&nbsp;选项2    <td><input class="inputcheckbox" type="checkbox" name="ids[1][3]"/>&nbsp;选项3 <tr id="node-10" class="child-of-node-1">    <td>总类一 分类一</td>    <td><input class="inputcheckbox" type="checkbox" name="ids[10][1]"/>&nbsp;选项1    <td><input class="inputcheckbox" type="checkbox" name="ids[10][2]"/>&nbsp;选项2    <td><input class="inputcheckbox" type="checkbox" name="ids[10][3]"/>&nbsp;选项3 <tr id="node-11" class="child-of-node-1">    <td>总类一 分类二</td>    <td><input class="inputcheckbox" type="checkbox" name="ids[11][1]"/>&nbsp;选项1    <td><input class="inputcheckbox" type="checkbox" name="ids[11][2]"/>&nbsp;选项2    <td><input class="inputcheckbox" type="checkbox" name="ids[11][3]"/>&nbsp;选项3     <tr id="node-2">    <td>总类二</td>    <td><input class="inputcheckbox" type="checkbox" name="ids[2][1]"/>&nbsp;选项1    <td><input class="inputcheckbox" type="checkbox" name="ids[2][2]"/>&nbsp;选项2    <td><input class="inputcheckbox" type="checkbox" name="ids[2][3]"/>&nbsp;选项3 <tr id="node-20" class="child-of-node-2">    <td>总类二 分类一</td>    <td><input class="inputcheckbox" type="checkbox" name="ids[20][1]"/>&nbsp;选项1    <td><input class="inputcheckbox" type="checkbox" name="ids[20][2]"/>&nbsp;选项2    <td><input class="inputcheckbox" type="checkbox" name="ids[20][3]"/>&nbsp;选项3   <tr id="node-3">    <td>总类二</td>    <td><input class="inputcheckbox" type="checkbox" name="ids[3][1]"/>&nbsp;选项1    <td><input class="inputcheckbox" type="checkbox" name="ids[3][2]"/>&nbsp;选项2    <td><input class="inputcheckbox" type="checkbox" name="ids[3][3]"/>&nbsp;选项3 </table>

因为是程序循环出来的,td选项的属性name class都不能改变,仅用现在提供的属性结构,能不能做到点选总类子选项,分类的子选项也会选中

例:点选总类一下的选项1,总类一下所有分类的选项1也会被选中

<script type="text/javascript">      function getElementsByClassName(className, element) {         var children = (element || document).getElementsByTagName('*');         var elements = new Array();                 for (var i = 0; i < children.length; i++) {             var child = children[i];             var classNames = child.className.split(' ');             for (var j = 0; j < classNames.length; j++) {                 if (classNames[j] == className) {                     elements.push(child);                     break;                 }             }         }         return elements;     }    window.onload = function(){         var table = document.getElementById('table');         table.onclick = function(e){             e = e || window.event;             var tar = e.target || e.srcElement;             if(tar.tagName!='INPUT'){                 return;             }             if(tar.type!='checkbox'){                 return;             }                           var parent = tar.parentNode.parentNode;             var isParent = parent.className == '' && parent.className.indexOf('child-of-node')==-1             if(isParent){                 var parentId = parent.id.split('-')[1];                 var childClass = 'child-of-node-'+parentId;                 var tarOption = tar.getAttribute('option');                 var childTr = getElementsByClassName(childClass,table),len=childTr.length;                 for(var i=0;i<len;i++){                     var childId = childTr[i].id.split('-')[1];                     var shouldCheckName = 'ids['+childId+']['+tarOption+']';                     var checkes = document.getElementsByName(shouldCheckName);                     var inputlen = checkes.length;                     for(var j=0;j<inputlen;j++){                         checkes[j].checked = tar.checked;                     }                 }             }         }     } </script>   <table id="table"> <tr id="node-1">    <td>总类一</td>    <td><input class="inputcheckbox" type="checkbox" name="ids[1][1]" option="1"/>&nbsp;选项1    <td><input class="inputcheckbox" type="checkbox" name="ids[1][2]" option="2"/>&nbsp;选项2    <td><input class="inputcheckbox" type="checkbox" name="ids[1][3]" option="3"/>&nbsp;选项3 </tr> <tr id="node-10" class="child-of-node-1">    <td>总类一 分类一</td>    <td><input class="inputcheckbox" type="checkbox" name="ids[10][1]"/>&nbsp;选项1    <td><input class="inputcheckbox" type="checkbox" name="ids[10][2]"/>&nbsp;选项2    <td><input class="inputcheckbox" type="checkbox" name="ids[10][3]"/>&nbsp;选项3 </tr> <tr id="node-11" class="child-of-node-1">    <td>总类一 分类二</td>    <td><input class="inputcheckbox" type="checkbox" name="ids[11][1]"/>&nbsp;选项1    <td><input class="inputcheckbox" type="checkbox" name="ids[11][2]"/>&nbsp;选项2    <td><input class="inputcheckbox" type="checkbox" name="ids[11][3]"/>&nbsp;选项3  </tr>    <tr id="node-2">    <td>总类二</td>    <td><input class="inputcheckbox" type="checkbox" name="ids[2][1]" option="1"/>&nbsp;选项1    <td><input class="inputcheckbox" type="checkbox" name="ids[2][2]" option="2"/>&nbsp;选项2    <td><input class="inputcheckbox" type="checkbox" name="ids[2][3]" option="3"/>&nbsp;选项3 </tr> <tr id="node-20" class="child-of-node-2">    <td>总类二 分类一</td>    <td><input class="inputcheckbox" type="checkbox" name="ids[20][1]"/>&nbsp;选项1    <td><input class="inputcheckbox" type="checkbox" name="ids[20][2]"/>&nbsp;选项2    <td><input class="inputcheckbox" type="checkbox" name="ids[20][3]"/>&nbsp;选项3 </tr> <tr id="node-3">    <td>总类二</td>    <td><input class="inputcheckbox" type="checkbox" name="ids[3][1]" option="1"/>&nbsp;选项1    <td><input class="inputcheckbox" type="checkbox" name="ids[3][2]" option="2"/>&nbsp;选项2    <td><input class="inputcheckbox" type="checkbox" name="ids[3][3]" option="3"/>&nbsp;选项3 </tr> </table>

无限级选中。

[1] [2] 下一页

设为首页 | 联系站长 | 友情链接 | 网站地图 |

copyright©youerw.com 优尔论文网 严禁转载
如果本毕业论文网损害了您的利益或者侵犯了您的权利,请及时联系,我们一定会及时改正。