简体   繁体   English

div标签没有出现在asp按钮上

[英]div tag not showing up on asp button click

I have the following code in script tag: 我在脚本标记中有以下代码:

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

and here is the button and the div tag: 这是按钮和div标签:

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

when I click the button, div tag is not showing up. 当我点击按钮时,div标签没有显示出来。 I have display:none; 我有显示:无; for div in css.. 为css中的div ..

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

Is going to take like 500 seconds to show up. 将需要500秒才能显示出来。

Try 尝试

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

The argument in show indicates how many milliseconds it takes before the element shows up. show中的参数表示元素显示之前需要多少毫秒。 Leaving no argument in show() defaults to .show(400) show()没有参数默认为.show(400)

You button is rendered by asp.net and it changes the id (unless you have set the static id mode) so when rendered id of the button will not be Button1 instead it will have other things appended to it (to avoid id duplication as much as possible). 你的按钮是由asp.net呈现的,它改变了id(除非你设置了静态id模式),所以当按钮的渲染id不是Button1它会附加其他东西(以避免id重复)尽可能)。 So use the ClientId to register the click handler. 因此,使用ClientId注册单击处理程序。 Also the duration for show animation is in milliseconds and you have it too long, just shorten it up a bit as well. show动画的持续时间以毫秒为单位,你有太长的时间,只是缩短了一点。

Try:- 尝试:-

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

Another approach it to provide a CssClass to your button and bind the handler to that as the selector. 另一种方法是为您的按钮提供CssClass并将处理程序绑定到选择器。

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

and

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

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

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