【问题标题】:Prevent pushing elements on hide and show - jQuery防止在隐藏和显示上推送元素 - jQuery
【发布时间】:2015-06-23 14:38:48
【问题描述】:

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

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内容如何重叠?

【问题讨论】:

    标签: javascript jquery html css fieldset


    【解决方案1】:

    如果您使用 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/

    【讨论】:

      猜你喜欢
      • 2012-08-28
      • 2012-08-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多