[英]How could I apply the class or the style to some HTML element in IE?
I'm doing an application that has to parse elements in an XML tree to HTML and in all the browsers it goes well but IE doesn't want to apply the styles to the elements. 我正在做一个应用程序,它必须将XML树中的元素解析为HTML,并且在所有浏览器中都运行良好,但是IE不想将样式应用于元素。 How could I fix this?
我该如何解决?
function add2Doc(elmnt, domDoc, newEl)
{
/*
* This function transform an
* element to into the an acceptable
* part of another document, I know
* exist some beatiful function called
* importNode but IE, like always doesn't
* accept.
*/
if (typeof newEl == 'undefined'){
var newEl = domDoc.createElement(elmnt.tagName);
}
if (elmnt.attributes.length > 0){
for (var cont = 0; cont < elmnt.attributes.length; cont++){
if (getBrowser() == 0){
/*
* This part of the code it's for the
* assholes of MS, what doesn't have
* any kind of consideration for
* the others, this kind of things
* consume resources and
* makes more slower the crap of IE.
*/
if (elmnt.attributes[cont].specified == true){
newEl.setAttribute(elmnt.attributes[cont].nodeName, elmnt.attributes[cont].nodeValue);
}
}else{
newEl.setAttribute(elmnt.attributes[cont].nodeName, elmnt.attributes[cont].nodeValue);
}
}
}
childs = elmnt.childNodes;
if (elmnt.childNodes.length > 0){
for (var cont = 0; cont < elmnt.childNodes.length; cont++){
child = elmnt.childNodes[cont];
if (child.nodeType == 1){
newChild = new add2Doc(child, domDoc, domDoc.createElement(child.tagName));
newEl.appendChild(newChild);
}else if(child.nodeType == 3){
if (getBrowser() == 1){
newEl.appendChild(domDoc.createTextNode(child.nodeValue));
}else{
if (newEl.tagName == 'STYLE'){
newEl.csstext = child.nodeValue;
}else if (newEl.tagName == 'SCRIPT'){
newEl.text = child.nodeValue;
} else{
newEl.innerText = child.nodeValue;
}
}
}
}
}
return newEl;
}
You can either apply browser specific stylesheets or put inline css hacks to fix these things. 您可以应用特定于浏览器的样式表,也可以放置内联CSS hack来解决这些问题。
http://www.maratz.com/blog/archives/2005/06/16/essentials-of-css-hacking-for-internet-explorer/ http://www.maratz.com/blog/archives/2005/06/16/essentials-of-css-hacking-for-internet-explorer/
In addition to having the appropriate CSS class in your stylesheet, you need to do this: 除了在样式表中包含适当的CSS类之外,您还需要执行以下操作:
var box = document.createElement("div");
box.className = 'your_css_class'; /*forces styling in ie*/
You should use conditional comments : 您应该使用条件注释:
<!--[if IE]>
<script type="text/javascript">
// do something here
</script>
<![endif]-->
Article here : http://www.quirksmode.org/css/condcom.html 文章在这里: http : //www.quirksmode.org/css/condcom.html
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.