在jquery中combobox多选的不兼容问题总结_jquery

WBOY
Release: 2016-05-16 17:07:20
Original
1521 people have browsed it

最近在IE10中开发jquery,关于jquery中combobox多选不能兼容的问题,进行一些总结。

当给combobox设置属性“multiple:true”时,IE10无法完成多选,其报错如下:

复制代码代码如下:

function _7e8(_7e9,_7ea){
var _7eb=$.data(_7e9,"combobox");
var opts=_7eb.options;
var _7ec=$(_7e9).combo("getValues");
var _7ed=_7ec.indexOf(_7ea+"");//10650行 这里报错
if(_7ed>=0){
_7ec.splice(_7ed,1);
_7e7(_7e9,_7ec);

也就是在F12中报不支持indexOf方法,现在对这种问题有两种解决方案:

1.修改源码

将以上代码修改为
复制代码代码如下:

function _7e8(_7e9,_7ea){
var _7eb=$.data(_7e9,"combobox");
var opts=_7eb.options;
var _7ec=$(_7e9).combo("getValues");
var _7ed = (function(arr,str){
str = str + "";
for(var i=0,l=arr.length;i if(arr[i] == str) return i;
}
return -1;
})(_7ec,_7ea);
if(_7ed >= 0){//修改于 2013-6-25 19:04
_7ec.splice(_7ed,1);
_7e7(_7e9,_7ec);
}


2.加入indexOf方法
复制代码代码如下:

if(!Array.prototype.indexOf){
Array.prototype.indexOf = function(target){
for(var i=0,l=this.length;i if(this[i] === target) return i;
}
return -1;
};
}


其实我还是蛮推荐第一种方法的,因为比较方便,我就是用的第一种方式。
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!