placeholder兼容到ie8
来源:互联网 发布:python的多线程对象 编辑:程序博客网 时间:2024/05/22 12:35
/** * 模拟placeholder * jQuery EnPlaceholder plug * EnPlaceholder是一个跨浏览器实现placeholder效果的jQuery插件 * version 1.0 * by Frans.Lee <dmon@foxmail.com> http://www.ifrans.cn * * 修正无placeholder显示undefined问题(lqy--http://fanshuyao.iteye.com/) * var defaultValue = $(_this).attr('placeholder'); * if(defaultValue != null && typeof(defaultValue) != "undefined"){ * * } */ (function ($) { $.fn.extend({ "placeholder":function (options) { options = $.extend({ placeholderColor:'#ACA899', isUseSpan:true, //是否使用插入span标签模拟placeholder的方式,默认false,默认使用value模拟 onInput:true //使用标签模拟(isUseSpan为true)时,是否绑定onInput事件取代focus/blur事件 }, options); $(this).each(function () { var _this = this; var supportPlaceholder = 'placeholder' in document.createElement('input'); if (!supportPlaceholder) { var defaultValue = $(_this).attr('placeholder'); //修正无placeholder时,显示undefined问题 if(defaultValue != null && typeof(defaultValue) != "undefined"){ var defaultColor = $(_this).css('color'); if (options.isUseSpan == false) { $(_this).focus(function () { var pattern = new RegExp("^" + defaultValue + "$|^$"); pattern.test($(_this).val()) && $(_this).val('').css('color', defaultColor); }).blur(function () { if ($(_this).val() == defaultValue) { $(_this).css('color', defaultColor); } else if ($(_this).val().length == 0) { $(_this).val(defaultValue).css('color', options.placeholderColor) } }).trigger('blur'); } else { var $imitate = $('<span class="wrap-placeholder" style="position:absolute;left:0; display:inline-block; overflow:hidden; color:'+options.placeholderColor+'; width:'+$(_this).outerWidth()+'px; height:'+$(_this).outerHeight()+'px;">' + defaultValue + '</span>'); $imitate.css({ 'margin-left':$(_this).css('margin-left'), 'margin-top':$(_this).css('margin-top'), 'font-size':$(_this).css('font-size'), 'font-family':$(_this).css('font-family'), 'font-weight':$(_this).css('font-weight'), 'padding-left':parseInt($(_this).css('padding-left')) + 2 + 'px', 'line-height':_this.nodeName.toLowerCase() == 'textarea' ? $(_this).css('line-weight') : $(_this).outerHeight() + 'px', 'padding-top':_this.nodeName.toLowerCase() == 'textarea' ? parseInt($(_this).css('padding-top')) + 2 : 0 }); $(_this).before($imitate.click(function () { $(_this).trigger('focus'); })); $(_this).val().length != 0 && $imitate.hide(); if (options.onInput) { //绑定oninput/onpropertychange事件 var inputChangeEvent = typeof(_this.oninput) == 'object' ? 'input' : 'propertychange'; $(_this).bind(inputChangeEvent, function () { $imitate[0].style.display = $(_this).val().length != 0 ? 'none' : 'inline-block'; }); } else { $(_this).focus(function () { $imitate.hide(); }).blur(function () { /^$/.test($(_this).val()) && $imitate.show(); }); } } } } }); return this; } }); })(jQuery); // 头部搜索框调用$('.searchipt').placeholder({isUseSpan:true});
0 0
- placeholder兼容到ie8
- IE8兼容placeholder
- placeholder兼容IE8解决方案
- placeholder兼容IE8代码
- css3新属性placeholder兼容ie7/ie8
- jquery input placeholder支持兼容ie7,ie8
- 关于html5标签PlaceHolder 兼容IE8,IE9浏览器
- javascript 解决IE8 兼容 placeholder 属性 含password
- jq操作代替placeholder属性(兼容ie8)
- input、textarea标签placeholder兼容IE8浏览器js插件代码
- 兼容placeholder
- 兼容placeholder
- placeholder 兼容
- placeholder兼容
- placeholder兼容
- 让IE8-的浏览器兼容到IE9
- IE8等不支持placeholder,通过javascript实现此功能,能够兼容多种浏览器
- 用简单的JS 间接解决IE8 中无法兼容placeholder的问题
- OpenCV 系列 --- 凸包
- 适配 iOS 10
- TCP/IP详解--拥塞控制 & 慢启动 快恢复 拥塞避免
- centos配置tomcat7
- PS颜色校正(Photoshop颜色显示偏色)
- placeholder兼容到ie8
- Spring AOP
- HTML第一章课后作业4
- Android Studio自动生成注释模板
- 一些常犯的错误
- Lua入门教程
- spring 容器的refresh方法
- 数据库分库分表(sharding)系列(二) 全局主键生成策略
- ffmpeg在Ubuntu14.04源码安装