开发者

jQuery plugin placeholder without using placeholder attribute

开发者 https://www.devze.com 2023-02-25 02:23 出处:网络
I\'m looking for a jQuery plugin开发者_StackOverflow社区 placeholder that doesn\'t use placeholder attribute.Should be fairly simple to build yourself — here\'s a quick example:

I'm looking for a jQuery plugin开发者_StackOverflow社区 placeholder that doesn't use placeholder attribute.


Should be fairly simple to build yourself — here's a quick example:

$.fn.placeholder = function(){
    return $(this).each(function(){
        $(this)
            .data('original-value', $(this).val())
            .focus(function(){
                var $input = $(this);
                if ($input.val() == $input.data('original-value'))
                    $input.val("");
            })
            .blur(function(){
                var $input = $(this);
                if ($.trim($input.val()) == "")
                    $input.val($input.data('original-value'));
            });
    });
};

$('input').placeholder(); 

http://jsfiddle.net/BrHjH/1

0

精彩评论

暂无评论...
验证码 换一张
取 消