[英]Apply css style to jquery plugin
I am trying to create a jquery treeview plugin for my current project. 我正在尝试为当前项目创建一个jquery树视图插件。 Plugin can run well with firefox at this moment;
目前,插件可以在firefox上正常运行; however, when running with IE, all the css style cannot be applied.
但是,使用IE运行时,无法应用所有的CSS样式。 For example, i define in the css file #button {...}, then when i generate the control with id="button", it cannot retrieve the style from the css.
例如,我在css文件#button {...}中定义,然后当我使用id =“ button”生成控件时,它无法从css中检索样式。 How can i solve this issue ?
我该如何解决这个问题?
This is some of my codes 这是我的一些代码
In the js file 在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;
};
and in the css file 并在css文件中
.button{...}
What about changing: 关于更改:
nBut.setAttribute("class", "button");
To: 至:
nBut.className = "button";
Since you are already including jQuery you can also make sure you are doing everything cross-platform: 由于您已经包含了jQuery,因此您还可以确保跨平台执行所有操作:
nBut = $("<button class='button'>Show Active Directory Tree</button>");
nDiv.append(nBut);
Note that this requires nDiv
to be a jQuery object ( nDiv = $('div')
). 请注意,这要求
nDiv
为jQuery对象( nDiv = $('div')
)。
I found this answer on stackoverflow: How can I reliably set the class attr w/JavaScript on IE, FF, Chrome, etc.? 我在stackoverflow上找到了以下答案: 如何在IE,FF,Chrome等上可靠地设置带有JavaScript的类attr?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.