我有下面的代码块。我已经通过调试,找到了导致IE6长时间延迟的片段。eval javascript函数IE6花费很长时间
基本上,代码循环遍历文档,将其转换为XML并发送至PDF。在Ubuntu和Firefox 4上需要3秒。在IE上它可能需要长达40秒的时间。
/**
* This function builds up the XML to be saved to the DM.
*/
function getXMLToSave(){
var text="<workbook><sheet><name>Adv4New</name>";
//show_props(document.adv4.row10col1, "document.adv4.row10col1");
for(i=1;i<157;i++){
text = text + "<row number='" + i + "'>";
for(j=1;j<=7;j++){
text = text + "<col ";
//alert(eval('document.adv4.row'+i+'col'+j+'.readonly'));
try{
text = text + "number='" + j + "' label='" + eval('document.adv4.row'+i+'col'+j+'.className')+ "'";
}
catch (e) {
text = text + "number='" + j + "' label=''";
}
try {
if(eval('document.adv4.row'+i+'col'+j).readOnly)
text = text + " type='readonly'";
else
text = text + " type=''";
}
catch (e) {
text = text + " type=''";
}
try {
text = text + " color='" + eval('document.adv4.row'+i+'col'+j+'.style.color') + "'";
}
catch (e) {
text = text + " color=''";
}
text = text + ">";
try {
// don't wrap in a CDATA (like previously), but run cleanNode
// this fixes html entities
var content = eval('document.adv4.row'+i+'col'+j+'.value');
text = text + cleanNode(content);
}
catch (e) {
text = text + "0";
}
text = text + "</col>";
}
text = text + "</row>";
}
text = text + "</sheet></workbook>";
return text;
}
我相信它的eval函数导致IE6的延迟。有没有一个很好的解决方案来解决这个问题。非常感谢
支持MS甚至不支持的浏览器? http://www.ie6countdown.com/ – epascarello
你的eval试图完成的究竟是什么?它看起来像你可以通过这样做轻松访问颜色属性:document.adv4 ['row'+ i +'col'+ j] .style.color –