2

我有一个这样的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。我想要一些像“失去焦点”这样的事件,我尝试过模糊但没有任何好处。

4

1 回答 1

1

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

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

于 2012-07-12T07:44:41.207 回答