input框失去获得焦点

来源:互联网 发布:中国海洋大学网络自助 编辑:程序博客网 时间:2024/05/17 04:29

$(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为空,加入缺省提示;



原创粉丝点击