当前位置:Gxlcms > JavaScript > 在jquery中combobox多选的不兼容问题总结

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

时间:2021-07-01 10:21:17 帮助过:5人阅读

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

当给combobox设置属性“multiple:true”时,IE10无法完成多选,其报错如下:
代码如下:
  1. <br>function _7e8(_7e9,_7ea){ <br>var _7eb=$.data(_7e9,"combobox"); <br>var opts=_7eb.options; <br>var _7ec=$(_7e9).combo("getValues"); <br>var _7ed=_7ec.indexOf(_7ea+"");//10650行 这里报错 <br>if(_7ed>=0){ <br>_7ec.splice(_7ed,1); <br>_7e7(_7e9,_7ec); <br> <br>也就是在F12中报不支持indexOf方法,现在对这种问题有两种解决方案: <br><br>1.修改源码 <br><br>将以上代码修改为 <br><span><u></u></span> 代码如下:<pre class="brush:php;toolbar:false layui-box layui-code-view layui-code-notepad"><ol class="layui-code-ol"><li><br><strong>function _7e8(_7e9,_7ea){ <br>var _7eb=$.data(_7e9,"combobox"); <br>var opts=_7eb.options; <br>var _7ec=$(_7e9).combo("getValues"); <br>var _7ed = (function(arr,str){ <br>str = str + ""; <br>for(var i=0,l=arr.length;i<l;i++){ <br>if(arr[i] == str) return i; <br>} <br>return -1; <br>})(_7ec,_7ea); <br>if(_7ed >= 0){//修改于 2013-6-25 19:04 <br>_7ec.splice(_7ed,1); <br>_7e7(_7e9,_7ec); <br>}</strong> <br> <br>2.加入indexOf方法 <br><span><u></u></span> 代码如下:<pre class="brush:php;toolbar:false layui-box layui-code-view layui-code-notepad"><ol class="layui-code-ol"><li><br><strong>if(!Array.prototype.indexOf){ <br>Array.prototype.indexOf = function(target){ <br>for(var i=0,l=this.length;i<l;i++){ <br>if(this[i] === target) return i; <br>} <br>return -1; <br>}; <br>}</strong> <br> <br>其实我还是蛮推荐第一种方法的,因为比较方便,我就是用的第一种方式。</li><li> </li><li> </li></ol></pre></li></ol></pre>

人气教程排行