JavaScript运行时错误:'Blur'未定义

时间:2014-04-23 22:58:25

标签: javascript html asp.net css

我一直试图让我的文字在我的文本框中加水印,并且已经出现了一些问题。

我是否必须在我的代码中的某处引用onbluronfocus,因为当我尝试点击相关文本框时它会中断。

这是我的代码,当我点击文本框时它就会中断。

HTML

<asp:TextBox runat="server" ID="tb_Username" onfocus="Focus(this.id,'Username')" onblur="Blur(this.id,'Username')" CssClass="WaterMarkedTextBox">Username</asp:TextBox>

脚本

window.Focus = function (objname, waterMarkText) {
 obj = document.getElementById(objname);
   if (obj.value == waterMarkText) {
    obj.value = "";
    obj.className = "NormalTextBox";
    if (obj.value == "Username" || obj.value == "" || obj.value == null) {
        obj.style.color = "black";
    }
  }
}

window.Blur = function (objname, waterMarkText) {
 obj = document.getElementById(objname);
  if (obj.value == "") {
    obj.value = waterMarkText;
    if (objname != "txtPwd") {
        obj.className = "WaterMarkedTextBox";
    }
    else {
        obj.className = "WaterMarkedTextBoxPSW";
    }
}
else {
    obj.className = "NormalTextBox";
}

if (obj.value == "Username" || obj.value == "" || obj.value == null) {
    obj.style.color = "gray";
 }
}

CSS

       .WaterMarkedTextBox
    {
        height: 16px;
        width: 168px;
        padding: 2px 2 2 2px;
        border: 1px solid #BEBEBE;
        background-color: #F0F8FF;
        color: gray;
        font-size: 8pt;
        text-align: center;
    }
    .WaterMarkedTextBoxPSW
    {
        background-position: center;
        height: 16px;
        width: 168px;
        padding: 2px 2 2 2px;
        border: 1px solid #BEBEBE;
        background-color: #F0F8FF;
        color: white;
        vertical-align: middle;
        text-align: right;
        background-image: url(Images/psw_wMark.png);
        background-repeat: no-repeat;
    }
    .NormalTextBox
    {
        height: 16px;
        width: 168px;
    }

编辑:

<link rel="stylesheet" type="text/css" href="StyleSheet.css">
<link rel="javascript" type="text/javascript" href="Scripts/LoginValidation.js" />

是的,我知道此代码在线

0 个答案:

没有答案