input placeholder兼容ie10以下
代码如下:
if( /msie/.test(navigator.userAgent.toLowerCase()) && $.browser.version.slice(,) < ) {
$('input[placeholder]').each(function(){ var input = $(this); $(input).val(input.attr('placeholder')); $(input).focus(function(){
if (input.val() == input.attr('placeholder')) {
input.val('');
}
}); $(input).blur(function(){
if (input.val() == '' || input.val() == input.attr('placeholder')) {
input.val(input.attr('placeholder'));
}
});
});
}
其中
$.brower.msie = /msie/.test(navigator.userAgent.toLowerCase()) //$.brower jquery1.90以上被去除 Jquery 1.9.0 以上版本 扩展使用 $.browser 方法
由于jQuery 1.9.0 以上版本 jquery去掉了对 $.browser 的支持,采用$.support 来判断浏览器类型。导致之前的很多插件报错
"Uncaught TypeError: Cannot read property 'msie' of undefined".
网上有很多解决办法如:
判断浏览器类型:
- <span style="white-space:pre"> </span>$.browser.mozilla = /firefox/.test(navigator.userAgent.toLowerCase());
- $.browser.webkit = /webkit/.test(navigator.userAgent.toLowerCase());
- $.browser.opera = /opera/.test(navigator.userAgent.toLowerCase());
- $.browser.msie = /msie/.test(navigator.userAgent.toLowerCase());
号后面的表达式返回的就是 true/false, 可以直接用来替换原来的 $.browser.msie 等。 检查是否为 IE6:
// Old
- <span style="white-space:pre"> </span>if ($.browser.msie && 7 > $.browser.version) {}
// New
- <span style="white-space:pre"> </span>if ('undefined' == typeof(document.body.style.maxHeight)) {}
检查是否为 IE 6-8:
- <span style="white-space:pre"> </span>if (!$.support.leadingWhitespace) {}
**************************************************************************
下面 我们采取的思路是 使用jquery的继承机制 对jquery 1.11.1版本 进行扩展 使其支持 $.browser 方法,已达到兼容之前组件的目的.
- jQuery.extend({
- browser: function()
- {
- var
- rwebkit = /(webkit)\/([\w.]+)/,
- ropera = /(opera)(?:.*version)?[ \/]([\w.]+)/,
- rmsie = /(msie) ([\w.]+)/,
- rmozilla = /(mozilla)(?:.*? rv:([\w.]+))?/,
- browser = {},
- ua = window.navigator.userAgent,
- browserMatch = uaMatch(ua);
- if (browserMatch.browser) {
- browser[browserMatch.browser] = true;
- browser.version = browserMatch.version;
- }
- return { browser: browser };
- },
- });
- function uaMatch(ua)
- {
- ua = ua.toLowerCase();
- var match = rwebkit.exec(ua)
- || ropera.exec(ua)
- || rmsie.exec(ua)
- || ua.indexOf("compatible") < 0 && rmozilla.exec(ua)
- || [];
- return {
- browser : match[1] || "",
- version : match[2] || "0"
- };
- }
将以上代码 保存成 jquery-browser.js 使用即可。
input placeholder兼容ie10以下的更多相关文章
- input placeholder 兼容问题
placeholder是html5出的新特性,ie9以下是不兼容的, 那么为了兼容ie9 我们需要对他做处理 //jq的处理方式$(function(){ jQuery('[placeholder] ...
- 兼容ie10以下版本的placeholder属性
<script src="${ctx }/js/jquery.placeholder.js" type="text/javascript">< ...
- IE9以下 placeholder兼容
//input placeholder兼容!(function ($, doc, win) { $.fn.placeholder = function () { var i = doc.createE ...
- 改进《完美让IE兼容input placeholder属性的jquery实现》的不完美
<完美让IE兼容input placeholder属性的jquery实现>中的代码在IE9以下浏览器中会出错,原因是因为ie9以下的浏览器对input的标签的解释不同. 例如对以下文本框的 ...
- 完美让IE兼容input placeholder属性的jquery实现
调用时直接引用jquery与下面的js就行了,相对网上的大多数例子来说,这个是比较完美的方案. /* * 球到西山沟 * http://www.cnzj5u.com * 2014/11/26 12:1 ...
- placeholder在不同浏览器下的表现及兼容方法 placeholder兼容
1.什么是placeholder? placeholder是html5新增的一个属性,当input或者textarea设置了该属性后,该值的内容将作为灰字提示显示在文本框中,当文本框获得焦点(或 ...
- placeholder 兼容 IE
placeholder 是 html5 的新属性,仅支持 html5 的浏览器才支持 placeholder,目前最新的 FF.Chrome.Safari.Opera 以及 IE10 都支持,IE6- ...
- HTML5 input placeholder 颜色修改示例
Chrome支持input=[type=text]占位文本属性,但下列CSS样式却不起作用: CSS 复制代码 代码如下: input[placeholder], [placeholder], *[p ...
- placeholder兼容
<!------------placeholder兼容-------------><script type="text/javascript"> $( ...
随机推荐
- list去从复
for(int i=0;i<queryList.size();i++){//去重 String time =queryList.get(i); i ...
- [No00006D]下载离线版的github for windows【以Github for Windows 3.0.110.为例】
目录 先上地址后讲原理: 原理: 11个目录的文件怎么一口气下载呢? 最后,把下好的文件批量名,同时将GitHub.exe.manifest也放到软件根目录下(与GitHub.exe同级): 今后的猜 ...
- 物联网平台设计心得:管中窥豹之HeartBeat
前言 在写这篇文章之前,我曾对HeartBeat做过诸多的研究,也做过诸多的项目,在这些项目中,有客户端为了维持状态,而定时向服务端发送的HeartBeat:有服务端为了维持客户端连接状态而处理Hea ...
- DbUtility v3
DbUtility v3 历史 七年前,也就是2007年,我在博客园写了一篇博文,开源并发布了恐怕是我第一个开源项目,DbUtility.其设计的初衷就是为了简化ADO.NET繁琐的数据库访问过程,提 ...
- js 获取时间间隔
现在感觉sublime IDE 用着比较方便,也比较美观,不知道大家用的是啥ide.
- PHP7中php.ini、php-fpm和www.conf的配置
引自:https://typecodes.com/web/php7configure.html 1 配置php.ini php.ini是php运行核心配置文件: ######避免PHP信息暴露在htt ...
- 利用phpize 外挂php扩展
如果你的php是手动编译安装的 ,可能有一些扩展一开始并没有开启,以后需要某扩展的时候又不想重新编译php,使用phpize可以动态添加扩展 以Ubuntu为例, 如果你是我这样安装php的 apt ...
- .net项目在linux平台的CI流程(基于Jenkins+mono+jexus)
内容较多,主要分为以下4方面内容: Jenkins的安装部署(centos 7+) .net在linux平台CI流程所需的插件管理&配置 Jenkins配置连接Gitlab(也可使用对应插件连 ...
- C#文本写入文件,追加写入文件
写入文件和这个对象 StreamWriter using (StreamWriter fs = new StreamWriter(path, true)) { fs.WriteLine(strLog) ...
- bzoj4726【POI2017】Sabota?
首先可以推出来如果i没有带头叛变,那么i的父亲也一定不会带头叛变,证明显然 所以最劣情况初始的叛徒肯定是叶子,并且带头叛变的人一定是从某个叶子往上走一条链 f[i]表示i不带头叛变的话最小的x 那么我 ...