0

我这里有一个情况:

这是我的菜单;它基本上是一个用于显示项目列表的 ul li 层次结构。

<ul id="treeMenu">

        <li id="Sites" class="contentContainer">
            <img src="images/plus.PNG">
            <input type="checkbox" value="Nichols San Juan Capistrano" id="Nichols San Juan Capistrano">Nichols San Juan Capistrano
            <br>

        <ul style="display: none" id="site1"> 


        <li id="Department" class="contentContainer">
            <img src="images/plus.PNG">
            <input type="checkbox" value="Endocrine Metabolism" id="Endocrine Metabolism">Endocrine Metabolism
            <br>

        <ul style="display: none" id="dept1">


            <li id="Instruments" class="contentContainer">
                <input type="checkbox" value="EZEMBN1" onclick="loadXMLInstrDoc(this)" id="EZEMBN1" name="instr">EZEMBN1
                <br>
            </li>

            <li id="Instruments" class="contentContainer">
                <input type="checkbox" value="EZEMTripti1" onclick="loadXMLInstrDoc(this)" id="EZEMTripti1" name="instr">EZEMTripti1
                <br>
            </li>

            <li id="Instruments" class="contentContainer">
                <input type="checkbox" value="EZEMTripti2" onclick="loadXMLInstrDoc(this)" id="EZEMTripti2" name="instr">EZEMTripti2
                <br>
            </li>

            <li id="Instruments" class="contentContainer">
                <input type="checkbox" value="EZEMTripti3" onclick="loadXMLInstrDoc(this)" id="EZEMTripti3" name="instr">EZEMTripti3
                <br>
            </li>

            <li id="Instruments" class="contentContainer">
                <input type="checkbox" value="EZEMTripti4" onclick="loadXMLInstrDoc(this)" id="EZEMTripti4" name="instr">EZEMTripti4
                <br>
            </li>

            <li id="Instruments" class="contentContainer">
                <input type="checkbox" value="EZEMMini1" onclick="loadXMLInstrDoc(this)" id="EZEMMini1" name="instr">EZEMMini1
                <br>
            </li>

            <li id="Instruments" class="contentContainer">
                <input type="checkbox" value="EZEMTripti5" onclick="loadXMLInstrDoc(this)" id="EZEMTripti5" name="instr">EZEMTripti5
                <br>
            </li>

            <li id="Instruments" class="contentContainer">
                <input type="checkbox" value="EZEMParul1" onclick="loadXMLInstrDoc(this)" id="EZEMParul1" name="instr">EZEMParul1
                <br>
            </li>

            <li id="Instruments" class="contentContainer">
                <input type="checkbox" value="EZEMPooja1" onclick="loadXMLInstrDoc(this)" id="EZEMPooja1" name="instr">EZEMPooja1
                <br>
            </li>

            <li id="Instruments" class="contentContainer">
                <input type="checkbox" value="EZEMRicha1" onclick="loadXMLInstrDoc(this)" id="EZEMRicha1" name="instr">EZEMRicha1
                <br>
            </li>

            <li id="Instruments" class="contentContainer">
                <input type="checkbox" value="EZEMPrahalad1" onclick="loadXMLInstrDoc(this)" id="EZEMPrahalad1" name="instr">EZEMPrahalad1
                <br>
            </li>

            <li id="Instruments" class="contentContainer">
                <input type="checkbox" value="Abhijeet123" onclick="loadXMLInstrDoc(this)" id="Abhijeet123" name="instr">Abhijeet123
                <br>
            </li>

        </ul>
        </li>

        </ul>
    </li>

        <li id="Sites" class="contentContainer">
            <img src="images/plus.PNG">
            <input type="checkbox" value="Nichols Valencia" id="Nichols Valencia">Nichols Valencia
            <br>

        <ul style="display: none" id="site2"> 


        <li id="Department" class="contentContainer">
            <img src="images/plus.PNG">
            <input type="checkbox" value="Automated Lab" id="Automated Lab">Automated Lab
            <br>

        <ul style="display: none" id="dept2">


            <li id="Instruments" class="contentContainer">
                <input type="checkbox" value="NEPH4" onclick="loadXMLInstrDoc(this)" id="NEPH4" name="instr">NEPH4
                <br>
            </li>

            <li id="Instruments" class="contentContainer">
                <input type="checkbox" value="SLIALTripti1" onclick="loadXMLInstrDoc(this)" id="SLIALTripti1" name="instr">SLIALTripti1
                <br>
            </li>

            <li id="Instruments" class="contentContainer">
                <input type="checkbox" value="SLIALBN1" onclick="loadXMLInstrDoc(this)" id="SLIALBN1" name="instr">SLIALBN1
                <br>
            </li>

            <li id="Instruments" class="contentContainer">
                <input type="checkbox" value="Neph5" onclick="loadXMLInstrDoc(this)" id="Neph5" name="instr">Neph5
                <br>
            </li>

        </ul>
        </li>

        </ul>
    </li>

        </ul>

我需要点击一个 plus img 并且它的孩子有 style=display:none; 应更改为 display:block ,直到最后一级和其他<li>

现在我这样做是为了<li>点击

 $(document).ready(function() {

            $("#treeMenu li").toggle(           

                  function() { // START FIRST CLICK FUNCTION
                      $(this).children('ul').slideDown()
                      if ($(this).hasClass('contentContainer')) { 
                          $(this).attr("checked","checked");  
                          $(this).removeClass('contentContainer').addClass('contentViewing');
                      }
                  }, // END FIRST CLICK FUNCTION

                  function() { // START SECOND CLICK FUNCTION
                      $(this).children('ul').slideUp()

                      if ($(this).hasClass('contentViewing')) {

                          $(this).removeClass('contentViewing').addClass('contentContainer');
                      }
                        } // END SECOND CLICK FUNCTIOn
                    ); // END TOGGLE FUNCTION 

        });

请有你的建议和解决方案流动......干杯!

请参考以下问题,这是我的要求:

http://stackoverflow.com/questions/11324224/javascript-create-3-level-tree-two-column-selection-boxes-html
4

0 回答 0