实用的placeholder插件,兼容IE下的placeholder,jquery插件

 

placeholder在IE下无法兼容 ,下面的插件很好的处理了这个问题,拿去不谢

 

 1 /*
 2  * jQuery placeholder, fix for IE6,7,8,9
 3  * @website itmyhome.com
 4  */
 5 var JPlaceHolder = {
 6     //检测
 7     _check : function(){
 8         return 'placeholder' in document.createElement('input');
 9     },
10     //初始化
11     init : function(){
12         if(!this._check()){
13             this.fix();
14         }
15     },
16     //修复
17     fix : function(){
18         jQuery(':input[placeholder]').each(function(index, element) {
19 
20             var self = $(this), txt = self.attr('placeholder');
21             self.wrap($('<div></div>').css({position:'relative', zoom:'1', border:'none', background:'none', padding:'none', margin:'none'}));
22             var pos = self.position(), h = self.outerHeight(true), paddingleft = self.css('padding-left');
23 
24             var holder = $('<span></span>').text(txt).css({position:'absolute', left:pos.left, top:pos.top, height:h, lienHeight:h, paddingLeft:paddingleft, color:'#aaa'}).appendTo(self.parent());
25             self.focusin(function(e) {
26                 holder.hide();
27             }).focusout(function(e) {
28                 if(!self.val()){
29                     holder.show();
30                 }
31             });
32             holder.click(function(e) {
33                 holder.hide();
34                 self.focus();
35             });
36         });
37     }
38 };
39 
40 //执行
41 jQuery(function(){
42     JPlaceHolder.init();    
43 });

 

转载于:https://www.cnblogs.com/wm218/p/9617243.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值