$(function(){
/*定义焦点和失去焦点事件*/
$.domFocusBlur = function($dom) {
if(!$dom) return;
var defVal = $dom.val();
$dom.on('focus',function(){
var curVal = $(this).val();
if(curVal==defVal){
$(this).val("");
$(this).css({"color": "#000"});
}
});
$dom.on('blur',function(){
var curVal = $(this).val();
if(curVal==""){
$(this).val(defVal);
$(this).css({"color": "#808080"});
}
});
};
/*调用方法*/
$.domFocusBlur($("input[name='frame-search']"));
场景:
鼠标点击文本框取得焦点,缺省提示消失;鼠标移开文本框失去焦点,如果input为空,加入缺省提示;