2013-04-22 57 views
1

我有一個遺留頁面,它使用了大量的原始JavaScript(沒有JS庫隱藏瀏覽器差異)。它動態地創建一個複選框,如下所示:以編程方式在IE 10中設置複選框檢查屬性

function createCheckbox(checkboxName, isChecked, onClickHandler) 
{ 
    var checkboxId = checkboxName + 'ChkBx'; 
    var chkbx; 

    if(Ext.isIE) 
    { 
     // Following code does not work in IE10 when NOT using compatibility view 
     // Throws JS error. Worked in IE9. 
     //if (isChecked) 
     //{ 
     // chkbx = document.createElement('<input id="' + checkboxId + '" type="checkbox" name="' + checkboxName + '" value="true" checked="checked" className="checkbox" />'); 
     //} 
     //else 
     //{ 
     // chkbx = document.createElement('<input id="' + checkboxId + '" type="checkbox" name="' + checkboxName + '" value="true" className="checkbox" />'); 
     //} 

     // Following code does not work in IE10 when using compatibility view 
     // isChecked == true does not product checked checkbox 
     chkbx = document.createElement('input'); 
     chkbx.id = checkboxId; 
     chkbx.name = checkboxName; 
     chkbx.value = 'true'; 
     chkbx.type = 'checkbox'; 
     chkbx.checked = isChecked; 
     chkbx.className = 'checkbox'; 
    } 
    else 
    { ... } 

    return chkbx;  
} 

我知道在IE10中,createElement()不再接受詳細的字符串參數。這就是爲什麼我改變了上面的代碼。我不明白的是爲什麼,它不尊重我將checked屬性設置爲true?人們應該如何指示覆選框應該被檢查?

+0

這應該做工精細; 「isChecked」的價值究竟是什麼? – Pointy 2013-04-22 19:53:10

回答

相關問題