【问题标题】:div tag not showing up on asp button clickdiv标签没有显示在asp按钮点击
【发布时间】:2013-11-28 05:46:55
【问题描述】:

我在脚本标签中有以下代码:

 $(document).ready(function () {
     $('#Button1').click(function () {
         $("#loading").show(500000);
     });
 });

这里是按钮和 div 标签:

 <asp:Button ID="Button1" runat="server" Text="View Summary" 
            onclick="Button1_Click" />
    </p>
    <div id="loading">Page is loading...</div>

当我单击按钮时,没有显示 div 标签。我有 display:none; 用于css中的div ..

【问题讨论】:

    标签: javascript jquery asp.net css


    【解决方案1】:

    你的按钮是由 asp.net 渲染的,它会改变 id(除非你设置了静态 id 模式),所以当渲染按钮的 id 不会是 Button1 而是它会附加其他的东西(到尽可能避免 id 重复)。所以使用ClientId 来注册点击处理程序。 show 动画的持续时间也以毫秒为单位,你的时间太长了,也可以缩短一点。

    试试:-

      $('#<%= Button1.ClientID %>').click(function () {
         $("#loading").show();
      });
    

    另一种方法是为您的按钮提供一个 CssClass 并将处理程序绑定到该按钮作为选择器。

     <asp:Button ID="Button1" runat="server" CssClass="Button1" Text="View Summary" 
            onclick="Button1_Click" />
    

     $('.Button1').click(function () {
         $("#loading").show();
      });
    

    【讨论】:

      【解决方案2】:
      $("#loading").show(500000);
      

      大约需要 500 秒才能显示出来。

      试试

      $("#loading").show();
      

      show 中的参数表示元素显示之前需要多少毫秒。在show() 中不保留任何参数默认为.show(400)

      【讨论】:

      • 谢谢特雷弗,我试过 $("#loading").show();仍然没有出现。
      猜你喜欢
      • 2014-06-09
      • 2017-06-08
      • 2016-10-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-01-02
      相关资源
      最近更新 更多