javascript 关注asp.net文本框的事件
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/5976020/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Focus out event of asp.net textbox
提问by smartDev
I want to call a javascript function on focus out of asp.net textbox. I want to do this on client side and not on server side.
我想从asp.net 文本框中调用一个javascript 函数来获得焦点。我想在客户端而不是在服务器端执行此操作。
回答by Town
回答by Govind Malviya
ASPX
ASPX
<asp:TextBox runat="server" ID="txt1"></asp:TextBox>
JQuery
查询
$('#<%=txt1.ClientID %>').blur(function() {
alert('Handler for .blur() called.');
});
回答by Ankit
<asp:TextBox ID="textbox1" runat="server" onblur="myFunction">
This will give you the event args also on the function.
这也会为您提供函数上的事件参数。
回答by Eric Burdo
You can also use the jQuery syntax to find any elements that END with the unique portion of your ID.
您还可以使用 jQuery 语法来查找以您的 ID 的唯一部分结束的任何元素。
$("[id$='textbox1']")).blur(function() {
alert('Handler for .blur() called.');
});
Depends on what functionality you are going for...
取决于您要使用的功能...
Also, if you have 1.4.3 or later of jQuery, you can use the focusout event (same concept as .blur, except it bubbles events up).
此外,如果您有 1.4.3 或更高版本的 jQuery,您可以使用 focusout 事件(与 .blur 的概念相同,但它会冒泡事件)。