2012-09-27 20 views
0

我有一個文本框的名字txtEmpcode.When它失去重點,我想,以示對上述功能的警報message.I've書面jQuery的,但它不工作...Textchange事件不會在jQuery中變得僵硬?

這是我的jQuery

$(document).ready(function(){ 
    var prm = Sys.WebForms.PageRequestManager.getInstance(); 
    //Raised before processing of an asynchronous postback starts and the postback request is sent to the server. 
    prm.add_beginRequest(BeginRequestHandler); 
    // Raised after an asynchronous postback is finished and control has been returned to the browser. 
    prm.add_endRequest(EndRequestHandler);  
    AutoComp();//Function for autocomplete textbox   

    $("#<%=txtEmpCode.ClientID").change(function(){   
     alert("hai"); 
    }); 

}); 

繼承人我的asp.net文本框

<asp:TextBox ID="txtEmpCode" runat="server" Width="250px" ToolTip="Enter EmployeeCode" 
AutoPostBack="True" ontextchanged="txtEmpCode_TextChanged"></asp:TextBox> 

回答

3

的第一個跡象,你跳過%>

$("#<%=txtEmpCode.ClientID%>").change(function(){   
     alert("hai"); 
    }); 
+1

完全忽略了那可能是一個問題! – Gromer

0

從您的TextBox中刪除您的ontextchanged="txtEmpCode_TextChanged"。或從您的jQuery中刪除您的change事件,並實施txtEmpCode_TextChanged的方法。請注意,文本框的change事件不處理所有情況。

這裏是一個文本框檢測改變文本一些好的信息:How to detect a textbox's content has changed

+0

我已經刪除了ontextchanged事件,但它仍然沒有觸發.......... – ksg

+0

你看過安東·巴舍赫耶夫指出了什麼嗎? – Gromer

+0

是的,我已添加'%>' – ksg

1

當一個元素失去了你可以使用jQuery中的.blur()函數來捕獲事件的焦點。例如:

$(document).ready(function() { 
     $('#idElement').blur(function() { 
      alert('i lost the focus \o/'); 
     }); 

}); 

對不起,英語不好。