只要把这段js粘贴到代码里,就可以实现效果了,具体的字体样子大小格式下面代码中有,根据自己的需求调整就好了
/*兼容ie8账号和密码的placeholder属性*/
var JPlaceHolder = {
_check: function () {
return 'placeholder' in document.createElement('input');
},
init: function () {
if (!this._check()) {
this.fix();
}
},
fix: function () {
jQuery(':input[placeholder]').each(function (index, element) {
var self = $(this), txt = self.attr('placeholder');
// 设置placeholder的位置,颜色,字体大小等
var holder = $('<span></span>').text(txt).css({
position: 'absolute',
left: '65px',
marginTop:'10px',
color: '#a9a9a9',
fontSize:'14px'
}).appendTo(self.parent());
self.focusin(function (e) {
holder.hide();
}).focusout(function (e) {
if (!self.val()) {
holder.show();
}
});
holder.click(function (e) {
holder.hide();
self.focus();
});
});
}
};
JPlaceHolder.init();
ie8兼容placeholder属性(一段js解决)
于 2019-09-04 15:50:32 首次发布