*IE8下,模拟placeholder效果
/*
*IE8下,模拟placeholder效果
*/
var JPlaceHolder = {
//检测
_check: function () {
return 'placeholder' in document.createElement('input');
},
//初始化
init: function (config) {
if (!this._check()) {
this.fix(config);
}
},
//修复
fix: function (config) {
jQuery(':input[placeholder]').each(function (index, element) {
var self = $(this), txt = self.attr('placeholder');
self.wrap($('<div class="u-holderWarp"></div>'));
var pos = self.position(), h = self.outerHeight(true), paddingleft = self.css('padding-left');
var buffer = config && config.topBuffer ? config.topBuffer : 10;
var holder = $('<span></span>').text(txt).css({ position: 'absolute', left: pos.left, height: h, lineHeight: h + "px", paddingLeft: paddingleft, color: '#aaa' }).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();
});
});
}
};

浙公网安备 33010602011771号