我有一个像这样的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后,当焦点位于文本框内时,会触发keyup。我想要一些像'失去焦点'这样的事件我尝试过模糊但没有任何好处。