会员
周边
众包
新闻
博问
闪存
所有博客
当前博客
我的博客
我的园子
账号设置
简洁模式
...
退出登录
注册
登录
.NET新手入门
Keep MOVEing.......永不止步!!!
博客园
首页
新随笔
联系
管理
订阅
ASP.NET 判断TextBox获得焦点事件
.aspx
<
div
>
<
asp:TextBox ID
=
"
txtUser
"
runat
=
"
server
"
Text
=
"
请输入用户名
"
></
asp:TextBox
>
<
br
/>
<
asp:TextBox ID
=
"
txtPwd
"
runat
=
"
server
"
TextMode
=
"
Password
"
></
asp:TextBox
>
</
div
>
.aspx.cs
protected
void
Page_Load(
object
sender, EventArgs e)
{
txtUser.Attributes.Add(
"
OnFocus
"
,
"
if(this.value=='请输入用户名') {this.value=''}
"
);
txtUser.Attributes.Add(
"
OnBlur
"
,
"
if(this.value==''){this.value='请输入用户名'}
"
);
txtPwd.Attributes.Add(
"
Value
"
,
"
请输入密码
"
);
txtPwd.Attributes.Add(
"
OnFocus
"
,
"
if(this.value=='请输入密码'){this.value=''}
"
);
}
实现效果和HTML控件效果
<
input
type
="text"
value
="请输入用户名"
onfocus
="if(value=='请输入用户名') {value=''}"
onblur
="if (value=='')
{value='请输入用户名'}"
/>
<
br
/>
<
input
type
="password"
value
="请输入密码"
onfocus
="if(value=='请输入密码') {value=''}"
onBlur
="if(value=='') {value='请输入密码'}"
/>
posted @
2009-05-17 16:14
.NET新手入门
阅读(
9745
) 评论(
2
)
编辑
收藏
举报
会员力量,点亮园子希望
刷新页面
返回顶部