防止在hide和show上推送元素 - jQuery

时间:2015-06-23 06:16:30

标签: javascript jquery html css fieldset

我正在隐藏并在点击图例时显示字段集内的内容。

JSFIDDLE示例

 var legends = document.getElementsByTagName("legend");

    for(var i=0; i<legends.length; i++)
    {
        legends[i].onclick = function()
        {
            var myDivs = this.parentNode.getElementsByTagName("div");
            var myDiv;

            if(myDivs.length > 0)
            {
                var myDiv = myDivs[0];

                if(myDiv.style.display == "")
                {
                    myDiv.style.display = "none"
                }
                else
                {
                    myDiv.style.display = "";
                }
            }
        }
    }

如何在显示内容后防止暂停?在我的示例中,示例内容在显示内容后被下推。如何重叠div内容?

1 个答案:

答案 0 :(得分:0)

如果您使用的是jquery,我建议您在弹出窗口中显示它。在html中尝试此代码,并确保引用jquery mobile:

<a href="#popupBasic" id="tet" data-rel="popup"><legend>One Legend</legend></a>

<div data-role="popup" id="popupBasic">
    <fieldset>

    <div>Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.e</div>

</fieldset>
</div>
<div><text>Sample Content</text></div>

jsfiddle:https://jsfiddle.net/UHn6q/51/