在jquery中combobox多選的不相容問題總結

來源:互聯網
上載者:User

在jquery中combobox多選的不相容問題總結

 最近在IE10中開發jquery,關於jquery中combobox多選不能相容的問題,進行一些總結,感興趣的朋友可以瞭解下

最近在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.修改源碼 

 

將以上代碼修改為 

代碼如下:

<strong>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<l;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); 

}</strong> 

 

2.加入indexOf方法 

代碼如下:

<strong>if(!Array.prototype.indexOf){ 

Array.prototype.indexOf = function(target){ 

for(var i=0,l=this.length;i<l;i++){ 

if(this[i] === target) return i; 

return -1; 

}; 

}</strong> 

 

其實我還是蠻推薦第一種方法的,因為比較方便,我就是用的第一種方式。 

 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.