<script type="text/javascript" language="javascript">
function cls() {
with (event.srcElement)
if (value == defaultValue) {
value = ""
this.style.color = '#000000'
}
}
function res() {
with (event.srcElement)
if (value == "") {
value = defaultValue
this.style.color = '#808080'
}
}
</script><asp:TextBox ID="tbname" runat="server" Width="128px" TabIndex="1" Text="用户名" onfocus="cls()" onblur="res()" ForeColor="Gray"></asp:TextBox>
<asp:TextBox ID="tbpassward" runat="server" Width="128px" TabIndex="1" Text="请输入密码" onfocus="cls()" onblur="res()" ForeColor="Gray"></asp:TextBox>我上面这种方式 页面加载时文本框内有文字 获得焦点时文字消失的功能是可以实现的,但是 当获得焦点时 文字的颜色还是gray 应该是黑色的才对2:<asp:TextBox ID="tbname" runat="server" Width="205px" Text="用户名" OnFocus="javascript:if(this.value=='用户名') {this.value='';this.style.color='#000000'}" OnBlur="javascript:if(this.value==''){this.value='用户名;
this.style.color='#808080'}" ForeColor="Gray"></asp:TextBox>
这种方式 是可以的 但是也没感觉和上面的有什么不同呀
还有一个问题就是 <asp:TextBox ID="tbpwd" runat="server" Width="128px" TextMode="Password"
TabIndex="2" Text="密码" OnFocus="javascript:if(this.value=='密码) {this.value='';this.style.color='#000000'}" OnBlur="javascript:if(this.value==''){this.value='密码;
this.style.color='#808080'}" ForeColor="Gray"></asp:TextBox> 如果TextMode="Password" 那么好像不起作用,请大家帮忙看看 谢谢
function cls() {
with (event.srcElement)
if (value == defaultValue) {
value = ""
this.style.color = '#000000'
}
}
function res() {
with (event.srcElement)
if (value == "") {
value = defaultValue
this.style.color = '#808080'
}
}
</script><asp:TextBox ID="tbname" runat="server" Width="128px" TabIndex="1" Text="用户名" onfocus="cls()" onblur="res()" ForeColor="Gray"></asp:TextBox>
<asp:TextBox ID="tbpassward" runat="server" Width="128px" TabIndex="1" Text="请输入密码" onfocus="cls()" onblur="res()" ForeColor="Gray"></asp:TextBox>我上面这种方式 页面加载时文本框内有文字 获得焦点时文字消失的功能是可以实现的,但是 当获得焦点时 文字的颜色还是gray 应该是黑色的才对2:<asp:TextBox ID="tbname" runat="server" Width="205px" Text="用户名" OnFocus="javascript:if(this.value=='用户名') {this.value='';this.style.color='#000000'}" OnBlur="javascript:if(this.value==''){this.value='用户名;
this.style.color='#808080'}" ForeColor="Gray"></asp:TextBox>
这种方式 是可以的 但是也没感觉和上面的有什么不同呀
还有一个问题就是 <asp:TextBox ID="tbpwd" runat="server" Width="128px" TextMode="Password"
TabIndex="2" Text="密码" OnFocus="javascript:if(this.value=='密码) {this.value='';this.style.color='#000000'}" OnBlur="javascript:if(this.value==''){this.value='密码;
this.style.color='#808080'}" ForeColor="Gray"></asp:TextBox> 如果TextMode="Password" 那么好像不起作用,请大家帮忙看看 谢谢
解决方案 »
- 必须包含中文的正则表达式
- 想组建学校网站
- 有人开发过点卡充值系统吗?
- Crystal Reports 在 web 上的Export
- 如何在datagrid中的格式化时间显示?
- 哪有crystal reports9.0(水晶报表)下载
- 如何调用web user control中的属性呢?
- 我在datagrid中加了2个template column,一个里面加了个textbox,一个是label。通过修改textbox里的值,使label显示不同的值。
- 高分求助:results[index].workId = reader.GetString(0); 这行为什么错误?
- 难道.NET平台想向Android系统app推送消息,只能用第三方的推送服务吗?
- asp.net js 读写文件
- 怎么可以获得当前是哪个控件得到焦点
<asp:TextBox ID="tbname" runat="server" Width="128px" TabIndex="1" Text="用户名" onfocus="cls()" onblur="res()" ForeColor="Gray"></asp:TextBox>
<asp:TextBox ID="tbpassward" runat="server" Width="128px" TabIndex="1" Text="请输入密码" onfocus="cls()" onblur="res()" ForeColor="Gray"></asp:TextBox>
如果开启了脚本调试的话,会报错: 'this.style' 为空或不是对象
如果按照你的第一种方式写的话,建议改成这样: <script type="text/javascript">
function cls(tb) {
if (tb.value == tb.defaultValue) {
tb.value = ""
tb.style.color = '#000000'
}
}
function res(tb) {
if (tb.value == "") {
tb.value = tb.defaultValue
tb.style.color = '#808080' }
}
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:TextBox ID="tbname" runat="server" Width="128px" TabIndex="1" Text="用户名" onfocus="cls(this)" onblur="res(this)" ForeColor="Gray"></asp:TextBox>
<asp:TextBox ID="tbpassward" runat="server" Width="128px" TabIndex="1" Text="请输入密码" onfocus="cls(this)" onblur="res(this)" ForeColor="Gray"></asp:TextBox>
</div>
</form>
</body>
<asp:TextBox ID="tbpwd" runat="server" Width="128px" TextMode="Password"
TabIndex="2" Text="输入密码" onfocus="cls(this)" onblur="res(this)" ForeColor="Gray"></asp:TextBox>
当 TextMode="Password"时,它的value值是隐藏的,所以就不起作用了,不用管它
$.fn.water = function (options) {
// build main options before element iterationvar
opts = $.extend({}, $.fn.water.defaults, options);
return this.each(function () {
var target = $(this);
function clear() {
if (target.val() == opts.defaultText && target.hasClass(opts.waterCss)) {
target.val("").removeClass(opts.waterCss);
}
} function renderDefault() {
if ($.trim(target.val()) === '') {
target.val(opts.defaultText).addClass(opts.waterCss);
}
} // Bind the related event handlers
target.focus(clear);
target.blur(renderDefault);
target.change(renderDefault);
renderDefault();
}); };