选项卡输出的焦点丢失事件的Javascript

Javascript on lost focus event for tab out

本文关键字:失事 事件 Javascript 焦点 输出 选项      更新时间:2023-09-26

我有一个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>

我正在使用on keyup事件,这样如果用户按tab键在文本框之间移动,则文本会添加到文本框中,但当按下tab键后我的焦点在文本框内时,on keyup会被触发。我想要一些事件,比如"失焦",我试过模糊,但没有任何好处。

当用户离开输入字段时,java脚本中会触发模糊事件。

http://www.w3schools.com/jsref/event_onblur.asp