从网上找的代码,自己封装了一下(前提:引用jQuery库)
方法1:
HTML:
javascript:
function InputStyleChange(id,p,c1,c2){
//函数
var placeholder = p;
var inputname = id;
inputname.onfocus = function(){
if ( this.value == placeholder ) {
this.value = '';
this.style.color = c1;
}
};
inputname.onblur = function(){
if (!this.value) {
this.value = placeholder;
this.style.color = c2;
}
};
if (inputname.value == placeholder) {
inputname.style.color = c2;
}
}
$(function){
InputStyleChange($('#tel')[0],'phone','#323232','#b4b4b4');
//调用函数
//修改默认显示文字需要与Html表单默认文字对应
})