DIV CSS 佈局教程網

 DIV+CSS佈局教程網 >> 網頁腳本 >> JavaScript入門知識 >> 關於JavaScript >> js用於樹型結構級聯選擇
js用於樹型結構級聯選擇
編輯:關於JavaScript     

<html>

<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>及聯選擇-用於權限選擇比較合適</title>
</head>

<body>
<ul id="tree">
    <li><input type=checkbox>
        <ul>
            <li><input type=checkbox>
                <ul>
                    <li><input type=checkbox></li>
                    <li><input type=checkbox></li>
                </ul>
            </li>
        </ul>
    </li>
</ul>
</body>
<script language="javascript">

var arr = tree.getElementsByTagName('input')
for(var i=0; i<arr.length; i++){
    var input = arr[i]
    if(input.type = 'checkbox'){
        input.onclick = ClickInput
    }
}

function ClickInput(){
    var li = this.parentElement;
    var arr = li.getElementsByTagName('input')
    for(var i=0; i<arr.length; i++){
        var input = arr[i]
        if(input.type == 'checkbox'){
            input.checked = this.checked
        }
    }
    var li = li.parentElement.parentElement
   
    while(li.tagName.toLowerCase() == 'li'){
        var input = li.childNodes[0]
        if(input.tagName.toLowerCase() == 'input'){
            input.checked = this.checked
        }
        li = li.parentElement.parentElement
    }
}

</script>
</html>

XML學習教程| jQuery入門知識| AJAX入門| Dreamweaver教程| Fireworks入門知識| SEO技巧| SEO優化集錦|
Copyright © DIV+CSS佈局教程網 All Rights Reserved