简体   繁体   English

在页面加载时隐藏Div控件

[英]Hide Div Control on Page Load

$(function () {
        $("#divLimitPrice").hide();
        $('#divLimitPrice').hide(); //even tried it with ''
    });

 <div id="divLimitPrice">Limit Price<br />
 <asp:TextBox ID="txtLimitPrice" runat="server"></asp:TextBox>
 </div>

My understanding is that this is supposed to work..... it wants to fight me. 我的理解是,这应该有效.....它想与我抗争。 Any way to beat it into submission? 有什么办法可以击败它提交? Thanks all! 谢谢大家! - G - G

It will flicker if you use JS as the script has to load first which means until it's loaded the div will remain visible on the DOM. 如果您使用JS,它将首先闪烁,因为脚本必须首先加载,这意味着在加载之前,div将在DOM上保持可见。

The easiest way to do this is to give your div a CSS class of display none like following. 最简单的方法是为div提供一个CSS类的display类,如下所示。 That way when the page is loaded it will already be hidden. 这样,当页面被加载时,它将已经被隐藏。

<div id="divLimitPrice" class="hide-div">Limit Price<br />

 hide-div { 
     display: none;
 }

When you need it to be shown you can use jQuery as follows: 当需要显示它时,可以使用jQuery,如下所示:

$('#divLimitPrice').removeClass('hide-div')

Hope this helps. 希望这可以帮助。

Try this: 尝试这个:

 <div id="divLimitPrice">Limit Price<br />
 <asp:TextBox ID="txtLimitPrice" runat="server"></asp:TextBox>
 </div>
<script>
    $(function () {
            $("#divLimitPrice").hide();
        });
</script>

I think your problem is the JS is executing before the page loads. 我认为您的问题是页面加载之前JS正在执行。

Try this: 尝试这个:

$(document).ready(function(){
  $("#divLimitPrice").hide();
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM