0

我有一個jQuery的自動完成工作在大多數瀏覽器,但只有一種工作在IE6,7,8(工程在IE9) 選擇第一個值後,如果我按向下箭頭以獲取可能值的列表。我列出了一個項目,即已經選擇的項目。我想要整個列表。jQuery UI的自動完成和IE6中的多個值,7,8

function split(term){ 
    return term.split(/,\s*/); 
} 

control.autocomplete({ 
     minLength: minLength, 
     source: function (request, response) { 
      // delegate back to autocomplete, but extract the last term 
      response($.ui.autocomplete.filter(
       values, split(request.term).pop())); 
     }, 
     select: function (event, ui) { 
      var terms = split(this.value); 
      // remove the current input 
      terms.pop(); 
      // add the selected item 
      terms.push(ui.item.value); 
      // add placeholder to get the comma-and-space at the end 
      terms.push(""); 
      this.value = terms.join(", "); 
      updateConfiguration(); 
      return false; 
     } 
    }); 

回答

0

事實證明,IE6,7和8處理與IE9,Chrome和FF不同的分割函數中的正則表達式。如果最後一個元素只包含空格,那麼它將被省略。

改變splite功能可按到低於固定此

function split(val) { 
    //IE deviates from all other browser if the last entry is empty 
    var temp = val.trim(); 
    var endsWithComma = temp.substring(temp.length-1) === ","; 
    temp = endsWithComma ? temp.substring(0,temp.length-1) : temp; 
    var values = temp.split(/,\s*/); 
    if(endsWithComma) 
     values[values.length] = " "; 
    return values; 
}