2011-12-20 89 views
4

我對JSON有以下查詢:選擇的選項不工作在IE瀏覽器,而在Firefox中工作。JSON:選擇的選項不工作在IE中,而在Firefox中工作

我有示例數據,如:

var columnDefs = [... 
{"name":"childPerformancePrice", "label":"Cosell Price", "type":"int", "control":"select", "options":performancePrices, "align":"left", "default":"", "required":false,"size": 6}, 
...] 

性能下拉列表,如:

function getPerformancePrices(){ 
    ...... 
     $.getJSON("?data=performancePrices", function(list) { 
      performancePrices.push([0, ""]); 
      $.each(list, function(index, item) { 
      performancePrices.push([item.id, item.description]); 
      performancePrices.sort(); 

      }); 
     ... 
     }); 
    } 

例如JSON數據,如JSON.stringify(columnDefs[index])

{"name":"childPerformancePrice", "label":"Cosell Price", "type":"int", "control":"select", "options":[[0,""],[15000,"Band 1"],[15001,"Band 2"],[15002,"Band 3"]],"align":"left", "default":"", "required":false,"size": 6} 

問:爲什麼下列選定的選項在編輯期間在IE中工作時不工作(即,在IE中不能正確選擇)好在Firefox?

function selectCell(oColumnDef, value) { 
    var oSelect = createNamedElement("select", oColumnDef["name"]); 
    if (value == undefined) { 
     value = ""; 
    } 
    $.each(oColumnDef["options"], function(index, item) { 
     var oOption = document.createElement("option"); 
     oOption.value = item[0]; 
     oOption.text = item[1]; 
     if (item[1] == value) { 
      oOption.selected = true; 
     } 
     oSelect.options.add(oOption); 
    }); 

回答

1

我能想到的唯一的事情就是,因爲它在FF,而不是IE,還有一些關於你是如何創造這些選項,後者不喜歡。既然你已經使用jQuery,嘗試改變這一點:

var oOption = document.createElement("option"); 
oOption.value = item[0]; 
oOption.text = item[1]; 
if (item[1] == value) { 
    oOption.selected = true; 
} 
oSelect.options.add(oOption); 

要這樣:

var oOption = $("<option />", { "value": item[0], 
           "text": item[1], 
           "selected": item[1] === value 
           }); 
$(oSelect).append(oOption); 

與任何怪癖IE瀏覽器,前提是jQuery將鐵過來。

+0

僅供參考,提問者試圖在編輯中詢問後續問題;看[這裏](http://stackoverflow.com/suggested-edits/163337)。 – 2011-12-20 11:23:48

相關問題