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) {
if($(this).val()==null || $(this).val()==""){
var self = $(this), txt = self.attr('placeholder');
self.wrap($('<div></div>').css({display:'inline',position:'relative', zoom:'1', border:'none', background:'none', padding:'none', margin:'none'}));
var pos = self.position(), h = self.outerHeight(true), paddingleft = self.css('padding-left'),textIndent=self.css('text-indent'),fontsize=self.css('font-size');
var line='24px';
if(self.attr("data-lineheight")!=null){
line=self.attr("data-lineheight");
}
var holder = $('<span></span>').text(txt).css({position:'absolute',lineHeight: line, left:pos.left, top:pos.top, height:h, lienHeight:h, paddingLeft:paddingleft, color:'#aaa',textIndent:textIndent,fontSize:fontsize}).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();
});
}
});
}
};
IE支持placeholder属性,支持自定义属性
最新推荐文章于 2021-06-19 12:31:12 发布