【发布时间】:2012-07-11 22:16:30
【问题描述】:
我有一个这样的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。我想要一些像“失去焦点”这样的事件,我尝试过模糊但没有任何好处。
【问题讨论】:
标签: c# javascript asp.net