$(document).ready(function(){

     $("#biaoqian").val('这里是默认的灰色文字');

     $("#biaoqian").css('color','#ccc');

     $("#biaoqian").css('font-size','14px');

      $("#biaoqian").focus(function(){

              if(this.value == '这里是默认的灰色文字'){

                   this.value = '';

                   $("#biaoqian").css('color','#000');

              }

      });
$("#biaoqian").blur(function(){
if(this.value == null || this.value == ''){ this.value = '这里是默认的灰色文字'; $("#biaoqian").css('color','#ccc');
} }); });

适用于 input  和 textarea  等,只需提供一个id标签即可,  方法需写在ready里面

04-15 00:16