全部折叠后,可展开列表复选框消失

时间:2014-01-28 18:56:02

标签: javascript list checkbox expandable

我在javascript可扩展列表中有一个表单。在几个标题中,我有复选框和单选按钮。我还有一个展开全部并折叠所有按钮。我的问题是,在单击全部折叠按钮后,如果单击列表项,则复选框不会显示。如果我点击展开全部按钮,一切都会正常显示,但是我必须点击标题才能再次折叠它们。这是一个fiddle,可以重现问题。

编辑以澄清:只有在单击全部折叠,然后单击列表标题后才会出现此问题。子标题不再显示复选框。

HTML:

<body>
<div id="listContainer">
        <div class="listControl">
            <a id="expandList">Expand All</a>
            <a id="collapseList">Collapse All</a>
        </div>
        <form id="ColForm" action="Table.php" method="post"> <!--Organized list of collumns and filter options-->
        <ul id="expList">
        <li>Section heading
            <ul>
            <li><input type="checkbox" name="ColSelect" value="Name" form="ColForm"> <!--If checked, collumn will be included in final table--> Name
                <ul>
                <li>
                    <input type="text" name="Name" form="ColForm"><br> <!--filter parameter input-->
                </li>
                </ul>
            </li>
            <li><input type="checkbox" name="ColSelect" value="RA,Dec" form="ColForm">Another collumn
                <ul>
                <li>
                    <input type="radio" name="PoSearch" value="Range" form="ColForm">Radio button to select form type for this section<br>
                    <i>I have an option here
                    <input type="radio" name="Degs" value="Dec" form="ColForm">Option 1 
                    <input type="radio" name="Degs" value="Hex" form="ColForm">Option 2</i><br>
                    Text input 1<br>
                    <input type="text" name="RA" form="ColForm">deg<br>
                    Text input 2<br>
                    <input type="text" name="Dec" form="ColForm">deg<br>
                    <input type="radio" name="PoSearch" value="Area" form="ColForm">Second form option<br>
                    <i>Text input A</i><br>
                    <input type="text" name="Area" form="ColForm"><br>
                </li>
                </ul>    
            </li>
            </ul>
        </li>
        </ul>
    <input type="submit" value="submit" form="ColForm">
    </form>
</div>
</body>

CSS:

#expList ul, li {
    list-style: none;
    margin:0;
    padding:0;
    cursor: pointer;
}
#expList p {
    margin:0;
    display:block;
}
#expList p:hover {
    background-color:#121212;
}
#expList li {
    line-height:140%;
    text-indent:0px;
    background-position: 1px 8px;
    padding-left: 20px;
    background-repeat: no-repeat;
}

/* Collapsed state for list element */
#expList .collapsed {

}
/* Expanded state for list element
/* NOTE: This class must be located UNDER the collapsed one */
#expList .expanded {

}
#expList {
    clear: both;
}


.listControl{
  margin-bottom: 15px;
}
.listControl a {
    border: 1px solid #555555;
    color: #555555;
    cursor: pointer;
    height: 1.5em;
    line-height: 1.5em;
    margin-right: 5px;
    padding: 4px 10px;
}
.listControl a:hover {
    background-color:#555555;
    color:#222222; 
    font-weight:normal;
}

Javascript:

function prepareList() {
    $('#expList').find('li:has(ul)')
    .click( function(event) {
        if (this == event.target) {
            $(this).toggleClass('expanded');
            $(this).children('ul').toggle('medium');
        }
        //return false;
    })
    .addClass('collapsed')
    .children('ul').hide();

    //Create the button functionality
    $('#expandList')
    .unbind('click')
    .click( function() {
        $('.collapsed').addClass('expanded');
        $('.collapsed').children().show('medium');
    })
    $('#collapseList')
    .unbind('click')
    .click( function() {
        $('.collapsed').removeClass('expanded');
        $('.collapsed').children().hide('medium');
    }) 
};

$(document).ready( function() {
    prepareList()
});

0 个答案:

没有答案