[英]Apply css style to jquery plugin
我正在嘗試為當前項目創建一個jquery樹視圖插件。 目前,插件可以在firefox上正常運行; 但是,使用IE運行時,無法應用所有的CSS樣式。 例如,我在css文件#button {...}中定義,然后當我使用id =“ button”生成控件時,它無法從css中檢索樣式。 我該如何解決這個問題?
這是我的一些代碼
在js文件中
createControls = function() {
nDiv = document.createElement("div");
nTxt = document.createElement("input");
nTxt.setAttribute('id','txtAdVal');
nTxt.setAttribute('type','text');
nTxt.setAttribute('style' , "width:300px");
nBut = document.createElement("button");
nBut.innerHTML = "Show Active Directory Tree";
nBut.setAttribute("class", "button");
nDiv.appendChild(nTxt);
nDiv.appendChild(nBut);
$(nBut).bind('click', function(event) {
createTree();
});
return nDiv;
};
並在css文件中
.button{...}
關於更改:
nBut.setAttribute("class", "button");
至:
nBut.className = "button";
由於您已經包含了jQuery,因此您還可以確保跨平台執行所有操作:
nBut = $("<button class='button'>Show Active Directory Tree</button>");
nDiv.append(nBut);
請注意,這要求nDiv
為jQuery對象( nDiv = $('div')
)。
我在stackoverflow上找到了以下答案: 如何在IE,FF,Chrome等上可靠地設置帶有JavaScript的類attr?
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.