输入框获取焦点 显示/隐藏 value

HTML:

<input type="text" class="hint" id="hint" value="粘贴淘宝、天猫、聚划算的宝贝地址,如:Http://item.taobao.com..." name="q">

JS:

$(function() {
    var inputEl = $('#hint'),
        defVal = inputEl.val();
    inputEl.bind({
        focus: function() {
            var _this = $(this);
            if (_this.val() == defVal) {
                _this.val('').css({'color':'black'});
            }
        },
        blur: function() {
            var _this = $(this);
            if (_this.val() == '') {
                _this.val(defVal).css({'color':'#999999'});
            }
        }
    });
})

 

posted @ 2014-04-14 13:47  白小虫  阅读(334)  评论(0编辑  收藏  举报