<HTML> 给input文本框中添加灰色提示字

来源:互联网 发布:电视直播点播软件 编辑:程序博客网 时间:2024/05/16 11:43

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

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

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

写个小demo大家测试下:

window.onload=function() {
      $("input[placeholder=请输入密码]").hover(
            function() {
                $(this).bind("focus", function() {
                    $(this).attr("placeholder","");
                });
            },    
            function() {
                $(this).bind("blur", function() {
                    $(this).attr("placeholder","请输入密码");
                });
            }
        );
     
  }

1 0