Jquery实现IE6 7 8 兼容placeholder属性
来源:互联网 发布:linux ntp时间对时 编辑:程序博客网 时间:2024/05/20 16:37
var JPlaceHolder = { //检测 _check : function(){ return 'placeholder' in document.createElement('input'); }, //初始化 init : function(){ if(!this._check()){ this.fix(); } }, //修复,该方法简单,但是有一个弊端:不填写的时候输入框也有值,需要在提交表单的时候过滤掉默认值 fix : function(){ $('[placeholder]').focus(function() { var input = $(this); if (input.val() == input.attr('placeholder')) { input.val(''); input.removeClass('my-placeholder'); } }).blur(function() { var input = $(this); if (input.val() == '' || input.val() == input.attr('placeholder')) { input.addClass('my-placeholder'); input.val(input.attr('placeholder')); } }).blur(); }, //修复2,该方法不会出现上述弊端,但是如果输入框初始是隐藏的话,定位left 和 top可能会出现为0的情况。这时,可以默认显示输入框,再用js在页面加载完成后隐藏就可以了 fix : function(){ jQuery(':input[placeholder]').each(function(index, element) { var self = $(this), txt = self.attr('placeholder'); var pos = self.position(), h = self.height(), paddingleft = self.css('padding-left'), paddingtop = self.css('padding-top'); var holder = $('<span></span>').text(txt).css({position:'absolute', left:pos.left, top:pos.top, height:h, paddingLeft:paddingleft,paddingTop:paddingtop, color:'#aaa'}).appendTo(self.parent()); self.focus(function(e) { holder.hide(); }).blur(function(e) { if(self.val()){ holder.hide(); }else{ holder.show(); } }).blur(); holder.click(function(e) { holder.hide(); self.focus(); }); }); }};//调用$(function(){ JPlaceHolder.init();});//css.my-placeholder{color:#c6c6c6; }
0 0
- Jquery实现IE6 7 8 兼容placeholder属性
- jquery html5 实现placeholder兼容password ie6
- 让IE支持placeholder属性,兼容IE6,7,8,9
- html5 Placeholder属性兼容IE6、7方法
- placeholder 兼容 ie6/7/8/9
- IE6,7,8,9中H5属性placeholder不兼容问题
- HTML5属性placeholder,支持IE6、7、8浏览器
- jQuery placeholder, fix for IE6,7,8,9
- jQuery实现IE浏览器兼容placeholder效果
- 兼容IE6、7、8,FireFox,JQuery showModalDialog 实现 子页局部刷新父页面
- CSS hack 属性的使用(兼容IE6、7、8、9)
- CSS hack 属性(兼容IE6、7、8、9)
- 属性操作-浮动cssFloat(兼容IE6、7、8)
- Placeholder兼容IE6以及以上版本
- 使用jquery解决ie6、7、8、9版本不支持placeholder的问题。
- 使IE兼容placeholder属性
- 【jQuery】利用jTemplates实现兼容IE6的jQuery模板化
- 滤镜 兼容IE6,7,8
- 如何更专业的使用Chrome开发者工具
- 开启我的算法之旅!
- Adnroid Ratingbar 动态设置Star iamge
- Swift2的更改
- *args和**kwargs
- Jquery实现IE6 7 8 兼容placeholder属性
- linux编译调用静态库
- Libcurl C++使用
- annotation(@Retention)
- linux下如何批量修改权限
- iOS 程序退到后台长期运行
- java中获取spring中bean的几种方式
- 002.输出控制台传递参数
- 有关Html中<a>、<link>和<script>标签中相对路径与绝对路径的问题总结