第一种方法
思路是用js的focus和blur实现placeholder功能。
新建一个js文件
(function() {
if(!('placeholder' in document.createElement('input'))) {
$('input[placeholder],textarea[placeholder]').each(function() {
var that = $(this),
text = that.attr('placeholder');
if(that.val() === "") {
that.val(text).addClass('placeholder');
}
that.focus(function() {
if(that.val() === text) {
that.val("").removeClass('placeholder');
}
})
.blur(function() {
if(that.val() === "") {
that.val(text).addClass('placeholder');
}
});
});
}
})();
第二种方法
jQuery三方插件 jquery-placeholder