Losing focus in jquery Event We only need to use blur to bind, so that we can monitor the blur action of the input box in real time.
A supervisor text event
$(function () { $(':text').blur(function () { if ($.trim($(this).val())=='') { $(this).css('border', 'red'); } else { $(this).css('border','white'); } }); });
Instance
<script src="Scripts/jquery-1.4.1.js" type="text/javascript"></script> <script language="javascript" type="text/javascript"> //失去焦点时判断(一个公用的方法,在文本框里写事件调用这个方法) function OnFousFun(element1, element2, text) { if ($(element1).val() == "" || $(element1).val() == text) {//输入框里值为空,或者为一些特定的文字时,都提示输入不能为空 $(element2).html("输入不能为空"); return false; } else { $(element2).html(""); return true; } } </script>
Page code
<tr> <th> 校长证件号码</th> <td> <asp:TextBox ID="txtCardID" runat="server" CssClass="formbox" TabIndex="1" MaxLength="50" Text='15位或18位' onblur="OnFousFun('#ContentPlaceHolder1_txtCardID','#ContentPlaceHolder1_Label1','15位或18位')"> </asp:TextBox> <asp:Label ID="Label1" runat="server" ForeColor="Red"></asp:Label> </td> </tr>
Description: onblur is an event when the text box loses focus
The above is the detailed content of jquery lost focus event blur sample code sharing. For more information, please follow other related articles on the PHP Chinese website!