很多网站的文本框都有灰色提文字,一点即消失,鼠标移开又出现! 用HTML5 中的新属性placeholder实现。

将这段代码加载input中! 带js代码

1
<input type="text" placeholder="要显示的文字">

写个小demo大家测试下:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
window.οnlοad=function() {
$("input[placeholder=请输入密码]").hover(
function() {
$(this).bind("focus", function() {
$(this).attr("placeholder","");
});
},
function() {
$(this).bind("blur", function() {
$(this).attr("placeholder","请输入密码");
});
}
);

}