失去焦点后如何触发onkeyup事件?

时间:2014-10-25 15:54:00

标签: javascript html asp.net

我已经发了一个onkeyup事件,一旦我点击另一个文本框,然后再点击激活onkeyup的文本框,它就不会触发它。
但是,第一次单击文本框时它确实有效。
我的代码:

HTML:

<asp:UpdatePanel ID="UpdatePanel1" runat="server">
                <ContentTemplate>
                <span id="spanAvailability"></span>
                <br />
                <asp:TextBox ID="email" runat="server" AutoPostBack="true" onkeyup="checkUsernameUsage(this.value)" style="font-size: 20px; text-align:center; border-radius: 20px;" class="RegisterButton" ValidationGroup="registergroup" placeholder="What's your Email?"></asp:TextBox>
                <br />   
                <asp:Label ID="Label2" runat="server"></asp:Label>
                <br />
                </ContentTemplate>
                </asp:UpdatePanel>

使用Javascript:

<script type="text/javascript">
var usernameCheckerTimer;
                 var spanAvailability = $get("spanAvailability");

                 function checkUsernameUsage(username) {
                     clearTimeout(usernameCheckerTimer);
                     if (username.length == 0)
                         spanAvailability.innerHTML = "";
                     else {
                         spanAvailability.innerHTML = "<span style='color: #ccc;'>checking...</span>";
                         usernameCheckerTimer = setTimeout("checkUsernameUsage('" + username + "');", 750);
                     }
                 }

                 function checkUsernameUsage(username) {
                     // initiate the ajax pagemethod call
                     // upon completion, the OnSucceded callback will be executed
                     PageMethods.IsUserAvailable(username, OnSucceeded);
                 }

                 // Callback function invoked on successful completion of the page method.
                 function OnSucceeded(result, userContext, methodName) {
                     if (methodName == "IsUserAvailable") {
                         if (result == true)
                             spanAvailability.innerHTML = "<span style='color: Red;'>Unavailable</span>";
                         else
                             spanAvailability.innerHTML = "<span style='color: DarkGreen;'>Available</span>";
                     }
                 }
    </script>


有什么建议吗?

0 个答案:

没有答案