jQuery plugin placeholder without using placeholder attribute
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
精彩评论