改方法有局限性需和文本框内的数据比较
private void Page_Load(object sender, System.EventArgs e)
{
this.TextBox1.Attributes.Add("onclick","this.focus()");
this.TextBox1.Attributes.Add("onfocus","checkLogin(this,1,'123')");
this.TextBox1.Attributes.Add("onblur","checkLogin(this,2,'123')");
// 在此处放置用户代码以初始化页面
}
function checkLogin(userName,n,co)
{
if (n == 0 && userName.value ==co){userName.value="";}
if (n == 1){
if(userName.value ==co){userName.value="";}
}
if (n == 2 && userName.value == ""){userName.value =co;}
}
(感谢石哥的帮助!)
1
<body MS_POSITIONING="GridLayout">
2
<form id="Form1" method="post" runat="server">
3
<INPUT style="Z-INDEX: 101; LEFT: 64px; POSITION: absolute; TOP: 120px" type="button" value="Button"
4
onclick="xx()">
5
<asp:TextBox id="TextBox1" style="Z-INDEX: 102; LEFT: 248px; POSITION: absolute; TOP: 88px" runat="server"
6
onclick="xx(document.Form1.TextBox1.value)">请输入6位号码</asp:TextBox>
7
<asp:TextBox id="TextBox2" style="Z-INDEX: 103; LEFT: 176px; POSITION: absolute; TOP: 200px"
8
runat="server" onclick="xx(document.Form1.TextBox1.value)"></asp:TextBox>
9
</form>
10
<script language="javascript">
11
function xx(ss)
12
{
13
if(document.Form1.TextBox1.value==ss)
14
{
15
document.Form1.TextBox1.value='';
16
}
17
18
19
20
21
}
22
</script>
经过高人指点后改为
<body MS_POSITIONING="GridLayout">2
<form id="Form1" method="post" runat="server">3
<INPUT style="Z-INDEX: 101; LEFT: 64px; POSITION: absolute; TOP: 120px" type="button" value="Button"4
onclick="xx()">5
<asp:TextBox id="TextBox1" style="Z-INDEX: 102; LEFT: 248px; POSITION: absolute; TOP: 88px" runat="server"6
onclick="xx(document.Form1.TextBox1.value)">请输入6位号码</asp:TextBox>7
<asp:TextBox id="TextBox2" style="Z-INDEX: 103; LEFT: 176px; POSITION: absolute; TOP: 200px"8
runat="server" onclick="xx(document.Form1.TextBox1.value)"></asp:TextBox>9
</form>10
<script language="javascript">11
function xx(ss)12
{13
if(document.Form1.TextBox1.value==ss)14
{15
document.Form1.TextBox1.value='';16
}17
18
19
20
21
}22
</script>private void Page_Load(object sender, System.EventArgs e)
{
this.TextBox1.Attributes.Add("onclick","this.focus()");
this.TextBox1.Attributes.Add("onfocus","checkLogin(this,1,'123')");
this.TextBox1.Attributes.Add("onblur","checkLogin(this,2,'123')");
// 在此处放置用户代码以初始化页面
}
function checkLogin(userName,n,co)
{
if (n == 0 && userName.value ==co){userName.value="";}
if (n == 1){
if(userName.value ==co){userName.value="";}
}
if (n == 2 && userName.value == ""){userName.value =co;}
}
(感谢石哥的帮助!)

浙公网安备 33010602011771号