简体   繁体   English

即使将ClientIdMode更改为静态,jQuery单击事件也不会触发-ASP.NET

[英]jQuery click event not firing even after changing ClientIdMode to Static - ASP.NET

I am trying to use jQuery to show my loader when the login button is clicked, so I turned ClientIdMode = "Static" . 我试图使用jQuery在单击登录按钮时显示加载程序,所以我打开了ClientIdMode = "Static" The click event is still not firing and I'm having trouble figuring out what's going on: 点击事件仍然没有触发,我在弄清楚发生了什么时遇到了麻烦:

<asp:Button ClientIDMode="Static" ID="btnLogin" CssClass="btn btn-block btn-large" runat="server" Text="Login" OnClick="btnLogin_Click"></asp:Button>

jQuery: jQuery的:

$("#btnLogin").click(function() {
$("#loader").show();
});

CSS: CSS:

#loader {
animation: animate 1.5s linear infinite;
clip: rect(0, 80px, 80px, 40px); 
height: 80px;
width: 80px;
position: absolute;
left: calc(50% - 40px);
top: calc(90% - 40px);
display: none;
}

I haven't tried to use jQuery with web forms before so I may be missing something, but I can't find any solutions at this point. 我以前没有尝试过将jQuery与Web表单一起使用,因此可能会遗漏一些东西,但是目前我找不到任何解决方案。

Thanks 谢谢

This works if you change your background to red as an example. 例如,如果将背景更改为red ,则此方法有效。

http://jsfiddle.net/scrkd9e2/1/ http://jsfiddle.net/scrkd9e2/1/

Ensure that your button element is correctly named btnLogin and has not been modified by the ASP.NET framework. 确保您的按钮元素正确命名为btnLogin ,并且没有被ASP.NET框架修改。

If you're using jQuery 3.0. Alpha 如果您使用的是jQuery 3.0. Alpha jQuery 3.0. Alpha . jQuery 3.0. Alpha You should use addClass() and removeClass() rather than .show() 您应该使用addClass()removeClass()而不是.show()

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

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