asp文本框默认文本灰色,点击消失
作者:未知侠名时间:2022-11-19 07:08:32
如果不考虑旧版本浏览器兼容,可以直接用placeholder这个属性
<input type="text" name="username" placeholder="UID/用户名/Email" />或者有个jquery插件,我之前也写过一个jquery小组件
jQuery.extend({
supportPlaceholder:'placeholder' in document.createElement('input')
});
jQuery.fn.extend({
placeHolder:function(){
if(jQuery.supportPlaceholder)return this;
return this.each(function(i,o){
var placeholder = '';
if (o && (placeholder = o.getAttribute("placeholder"))) {
o.onfocus = function() {
if (this.value === placeholder) {
this.value = "";
}
this.style.color = '';
};
o.onblur = function() {
if (this.value === "") {
this.value = placeholder;
this.style.color = 'graytext';
}
};
if (o.value === "") {
o.value = placeholder;
o.style.color = 'graytext';
}
$(o.form).submit(function(){
if(o.value == placeholder){
o.value = '';
}
});
}
})
}
});使用方法
1. 在输入框上写上placeholder属性(像第一条那样子)
2. 调用js
3. jQuery('input').placeHolder()这个插件主要是对旧版本浏览器做了兼容。
<input type="text" name="username" placeholder="UID/用户名/Email" />或者有个jquery插件,我之前也写过一个jquery小组件
jQuery.extend({
supportPlaceholder:'placeholder' in document.createElement('input')
});
jQuery.fn.extend({
placeHolder:function(){
if(jQuery.supportPlaceholder)return this;
return this.each(function(i,o){
var placeholder = '';
if (o && (placeholder = o.getAttribute("placeholder"))) {
o.onfocus = function() {
if (this.value === placeholder) {
this.value = "";
}
this.style.color = '';
};
o.onblur = function() {
if (this.value === "") {
this.value = placeholder;
this.style.color = 'graytext';
}
};
if (o.value === "") {
o.value = placeholder;
o.style.color = 'graytext';
}
$(o.form).submit(function(){
if(o.value == placeholder){
o.value = '';
}
});
}
})
}
});使用方法
1. 在输入框上写上placeholder属性(像第一条那样子)
2. 调用js
3. jQuery('input').placeHolder()这个插件主要是对旧版本浏览器做了兼容。
- 站长提醒大家:以上内容,未识真伪,仅供参考。理性上网,以免过度。谨慎广告,危及钱财。
版权声明:本信息由系统自动搜集网络信息,本站尊重网络信息的版权问题,本站所有内容仅供学习使用,版权归原作者所有,若有来源错误或者侵犯您的合法权益,您可通过邮箱与我们取得联系,我们将及时进行处理。