2012-07-12 50 views
2

失去焦點事件中,我有一個這樣的javascript函數:的Javascript對標籤進行

ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "watermark", "function WaterMark(txtWaterMark, event, text) {if(event.type == 'keyup') {var charCode; if (event.charCode) { charCode = event.charCode;} else { charCode = event.keyCode; } if(charCode == 9 && txtWaterMark.value.length == 0) txtWaterMark.value = 'Pakistan';} if (txtWaterMark.value.length > 0 && event.type == 'mouseover') { txtWaterMark.style.color = '#c6c1c1'; } if (txtWaterMark.value.length > 0 && event.type == 'mouseout') { txtWaterMark.style.color = 'gray';} if (txtWaterMark.value.length == 0 && event.type == 'mouseout') {txtWaterMark.value = text; } if (event.type == 'focus') {txtWaterMark.style.color = 'gray'; if (txtWaterMark.value == text) { txtWaterMark.value = ''; } }}", true); 

,我稱它是這樣的:

<asp:TextBox ID="txtFirstName" runat="server" Width="110px" Text="First Name." 
       ForeColor="Gray" onmouseover="WaterMark(this, event,'First Name.');" onmouseout="WaterMark(this, event,'First Name.');" 
       onfocus="WaterMark(this, event,'First Name.');" onkeyup="WaterMark(this, event,'First Name.');" ToolTip="First Name." 
       ValidationGroup="CheckoutConfirm"></asp:TextBox> 

我使用keyup事件,這樣,如果用戶按tab鍵在文本框之間移動,然後文本被添加到文本框中,但是在按下tab鍵後,當我的焦點位於文本框內時,會彈出關鍵幀。我想要一些像'失去焦點'的事件我試圖模糊但沒有任何好處。

回答

相關問題