> php教程 > php手册 > 다단계 연계

다단계 연계

WBOY
풀어 주다: 2016-09-02 08:42:18
원래의
1107명이 탐색했습니다.

백엔드와 데이터베이스가 없는 순수 프론트엔드 코드를 직접 복사하여 다단계 연계가 가능합니다.
html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><br> <br>     <br>         <meta> <br>         JavaScript 자정다문화지원<br>         <script>var $ = 함수(id) {<br /> <br />                 반환 "문자열" == ID 유형 ? document.getElementById(id) : id;<br /> <br />             };<br /> <br />             함수 addEventHandler(oTarget, sEventType, fnHandler) {<br /> <br />                 if (oTarget.addEventListener) {<br /> <br />                     oTarget.addEventListener(sEventType, fnHandler, false);<br /> <br />                 } else if (oTarget.attachEvent) {<br /> <br />                     oTarget.attachEvent("on" + sEventType, fnHandler);<br /> <br />                 } 그밖에 {<br /> <br />                     oTarget["on" + sEventType] = fnHandler;<br /> <br />                 }<br /> <br />             };<br /> <br />             함수 Each(arrList, fun) {<br /> <br />                 for(var i = 0,<br />                 len = arrList.length; 나는 < 렌; i++) {<br />                     fun(arrList[i], i);<br />                 }<br /> <br />             };<br /> <br />             함수 GetOption(val, txt) {<br /> <br />                 var op = document.createElement("OPTION");<br /> <br />                 op.value = val;<br />                 op.innerHTML = txt;<br /> <br />                 반품 작업;<br /> <br />             };<br /> <br />             var 클래스 = {<br /> <br />                 생성: 함수() {<br /> <br />                     반환 함수() {<br /> <br />                         this.initialize.apply(this, 인수);<br /> <br />                     }<br /> <br />                }<br /> <br />             }<br /> <br />             Object.extend = 함수(대상, 소스) {<br /> <br />                 for(소스의 var 속성){<br /> <br />                     대상[속성] = 소스[속성];<br /> <br />                 }<br /> <br />                 돌아오는 목적지;<br /> <br />             }<br /> <br />             var CascadeSelect = Class.create();<br /> <br />             CascadeSelect.prototype = {<br /> <br />                 //select集合,菜单对象<br />                 초기화: 함수(arrSelects, arrMenu, 옵션) {<br /> <br />                     if (arrSelects.length <= 0 || arrMenu.length <= 0) return; //菜单对象<br /> <br />                     var oThis = this;<br /> <br />                     this.Selects = []; //선택합<br />                     this.Menu = arrMenu; //菜单对象<br /> <br />                     this.SetOptions(옵션);<br /> <br />                     this.Default = this.options.Default || [];<br /> <br />                     this.ShowEmpty = !!this.options.ShowEmpty;<br /> <br />                     this.EmptyText = this.options.EmptyText.toString();<br /> <br />                     //设置선택합화변화사례<br />                     각각(arrSelects,<br />                     함수(o, i) {<br /> <br />                         addEventHandler((oThis.Selects[i] = $(o)), "변경",<br />                         함수() {<br />                             oThis.Set(i);<br />                         });<br /> <br />                     });<br /> <br />                     this.ReSet();<br /> <br />                 },<br /> <br />                 //设置默认属性<br />                  SetOptions: 기능(옵션) {<br /> <br /> This.options = { //기본값<br />                           기본값: [],<br /> //기본값(순서대로)<br />                        ShowEmpty: false,<br /> > > 빈 텍스트: "선택하세요" //빈 값 표시 텍스트(ShowEmpty가 true인 경우 유효)<br />                     };<br /> <br />                    Object.extend(this.options, options || {});<br /> <br />                  },<br /> <br /> >                                                      재설정: function() {<br /> <br /> This.SetSelect(this.Selects[0], this.Menu, this.Default.shift());<br /> <br /> This.Set(0);<br /> <br />                  },<br /> <br /> // 모든 선택 설정 <br />                  설정: 함수(색인) {<br /> <br />                   var 메뉴 = this.Menu<br /> <br /> //첫 번째 선택은 처리할 필요가 없으므로 1부터 시작합니다<br /> for (var i = 1,<br /> Len = this.selects.length; i & lt; I ++) {<br /> <br /> If (메뉴.길이 > 0) {<br /> <br /> >                                                                                      var value = this.Selects[i - 1].value;<br /> <br /> If (값 != "") {<br /> <br /> 각(메뉴,<br /> 함수(o) {<br /> If (o.val == 값) {<br />메뉴 = o.menu || ~ ~                                                } ; <br /> } 그렇지 않으면 {<s> 메뉴 = [];<br />                                             } <br /> >                            If (i > index) {<br /> This.SetSelect(this.Selects[i], 메뉴, this.Default.shift());<br />                                             } <br /> } 그렇지 않으면 {<s> <br /> >                                                              This.SetSelect(this.Selects[i], [], "");<br /> <br />                                                 } <br />                   }<br /> <br /> >                                                                      This.Default.length = 0;<br /> <br />                  },<br /> <br />                                 //설정 선택<br />                   SetSelect: 기능(oSel, 메뉴, 값) {<br /> <br />                     oSel.options.length = 0;<br /> oSel.disabled = false;<br /> <br /> If (this.ShowEmpty) {<br />                      oSel.appendChild(GetOption("", this.EmptyText));<br />                   }<br /> <br /> If (menu.length <= 0) {<br /> oSel.disabled = true;<br />                      반품;<br />                   }<br /> <br /> 각(메뉴,<br />                     기능(o) {<br /> <br /> Var OP = GetOption(o.val, o.txt? O.TXT: o.val) <br /> Op.select = (값 == op.값) <br /> <br /> oSel.appendChild(op);<br /> <br />                      });<br /> <br />                  },<br /> <br /> >                                             추가: 기능(메뉴) {<br /> <br /> This.Menu[this.Menu.length] = 메뉴;<br /> <br /> This.ReSet();<br /> <br />                  },<br /> <br /> >                                                삭제: 함수(색인) {<br /> <br /> If (index < 0 || index >= this.Menu.length) return;<br /> <br /> for (var i = 인덱스,<br /> Len = this.Menu.Length-1; i & lt; This.Menu[i] = this.Menu[i + 1];<br />                   }<br /> <br /> This.Menu.pop()<br /> <br /> This.ReSet();<br /> <br />                 }<br /> <br />             };<br /> <br />              window.onload = function() {<br /> <br />                 var 메뉴 = [<br /> <br />                                                                         '발': '1',<br />                     'txt': '값'<br />                  },<br /> <br />                                                                          'val': '2 ->',<br />                    '메뉴': [<br /> <br />                     {<br />                         '발': '2_1'<br />                     },<br /> <br />                     {<br />                         '발': '2_2'<br />                     }<br /> <br />                     ]<br />                 },<br /> <br />                 {<br />                     '발': '3 ->',<br />                     '메뉴': [<br /> <br />                     {<br />                         '발': '3_1 ->',<br />                         '메뉴': [<br /> <br />                         {<br />                             '발': '3_1_1'<br />                         },<br /> <br />                         {<br />                             '발': '3_1_2'<br />                         }<br /> <br />                         ]<br />                     },<br /> <br />                     {<br />                         '발': '3_2'<br />                     }<br /> <br />                     ]<br />                 },<br /> <br />                 {<br />                     '발': '4 ->',<br />                     '메뉴': [<br /> <br />                     {<br />                        '발':'4_1 ->',<br />                         '메뉴': [<br /> <br />                         {<br />                             '발':'4_1_1 ->',<br />                             '메뉴': [<br /> <br />                             {<br />                                 '발': '4_1_1_1'<br />                             }<br /> <br />                             ]<br />                         }<br /> <br />                         ]<br />                     }<br /> <br />                     ]<br />                 }<br /> <br />                 ];<br /> <br />                 var sel = ["sel1", "sel2", "sel3", "sel4", "sel5"];<br /> <br />                 var val = ["3 ->", “3_1 ->", “3_1_2"];<br /> <br />                 var cs = new CascadeSelect(sel, 메뉴, {<br />                     기본값: 가을<br />                 });<br /> <br />                 $("btnA").onclick = function() {<br />                     cs.ShowEmpty = !cs.ShowEmpty;<br />                 }<br /> <br />                 $("btnB").onclick = function() {<br /> <br />                     cs.추가(<br /> <br />                     {<br />                         '발':'5 ->',<br />                         '메뉴': [<br /> <br />                         {<br />                            '발': '5_1 ->',<br />                             '메뉴': [<br /> <br />                             {<br />                                 '발': '5_1_1 ->',<br />                                 '메뉴': [<br /> <br />                                 {<br />                                     '발': '5_1_1_1 ->',<br />                                     '메뉴': [<br /> <br />                                     {<br />                                         '발': '5_1_1_1_1'<br />                                     }<br /> <br />                                     ]<br />                                 }<br /> <br />                                 ]<br />                             }<br /> <br />                             ]<br />                         }<br /> <br />                         ]<br />                     }<br /> <br />                     )<br /> <br />                 }<br /> <br />                 $("btnC").onclick = function() {<br /> <br />                     cs.삭제(3)<br /> <br />                 }<br /> <br />             }</script><br>         <style>.sel select{ width:100px;}</style> <br>    <br>         <div> <br>             <select></select><br>             <select></select><br>             <select></select><br>             <select></select><br>             <select></select><br>         </div> <br>         <br><br>         <div> <br>             <input><br>             <input><br>             <input> </div> <br>     본문><br>

원천:php.cn
본 웹사이트의 성명
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.
인기 추천
인기 튜토리얼
더>
최신 다운로드
더>
웹 효과
웹사이트 소스 코드
웹사이트 자료
프론트엔드 템플릿