我設置dinamically產生的選擇控制與下面的代碼的className屬性:JavaScript的設置className屬性爲Internet Explorer
oField.className ="select";
它適用於Firefox的不是IE瀏覽器。我怎樣才能在IE上設置這個屬性?
的代碼:
var oField = document.createElement("select");
if(browser == "IE"){
oField.size = 1;
oField.setAttribute("name","sele"+num);
oField.onChange = function(){
AggiungiRiga(oField.name,oField.value)
};
}
else{
oField.setAttribute("size",1);
oField.setAttribute("name","sele"+num);
oField.setAttribute("onChange","AggiungiRiga(this.name,this.value)");
}
oField.className ="select";
在這裏,我將其添加到文檔:
oTd1.appendChild(oField);
(oTd1
是<td>
元件,其中選擇控制必須的地方)。我知道代碼質量不好,原因是遺留代碼。
假設'oField'是一個HTMLElementNode,它應該在IE中工作得很好。你的問題可能在別處。 – Quentin
oField只是一個變量。我設置了ID,名稱,值,className,然後將其添加到文檔中。 –
顯示將「oField」設置爲某個值的代碼。 – Pointy