清除焦点的默认搜索字符串

$("#s")
.val("搜索...")
.css("color", "#ccc")
.focus(function(){
$(this).css("color", "black");
if ($(this).val() == "搜索...") {
$(this).val("");
}
})
.blur(function(){
$(this).css("color", "#ccc");
if ($(this).val() == "") {
$(this).val("搜索...");
}
});
  1. 设置字段值“搜索...”
  2. 当得到焦点领域,设置颜色为黑色。
  3. 如果值是默认字符下,将其删除。当失去焦点,设置颜色为浅灰色。
  4. 如果值是空的,回到默认值

posted on 2012-01-31 16:01  tianyaxiang  阅读(328)  评论(0编辑  收藏  举报

导航