我正在做一个应用程序,它必须将XML树中的元素解析为HTML,并且在所有浏览器中它都很顺利,但IE不希望将这些样式应用于元素。我怎么能解决这个问题?如何将类或样式应用于IE中的某个HTML元素?
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;
}
你能告诉你如何做到这一点? – Jarek 2010-08-11 19:15:51