【发布时间】:2014-02-14 21:41:24
【问题描述】:
我有一个在 Firefox 中运行的脚本,它使用通过 getElementsByClassName 提取的元素数组。 IE8 不支持此方法,因此我必须替换 querySelectorAll。我的问题是 querySelectorAll 创建了一个静态列表,而不是对实际元素的实时引用。
我的脚本
function subMenu(sCat,gCat,sh,gh,selection)
{
sElements = document.querySelectorAll('cat'+sCat);
gElements = document.querySelectorAll('cat'+gCat);
// sElements = document.getElementsByClassName('cat'+sCat);
// gElements = document.getElementsByClassName('cat'+gCat);
if(sh>0)
{
for(i=0;i<sElements.length;i++)
{
if(!(h = window.getComputedStyle(sElements[i],null).height)) {h=sElements[i].currentStyle;}
nh = parseInt(h.replace("px",""))-4;
sElements[i].style.height = nh+"px";
}
sh=sh-4;
}
if(gh<100)
{
for(i=0;i<gElements.length;i++)
{
if(!(h = window.getComputedStyle(gElements[i],null).height)) {h=gElements[i].currentStyle;}
nh = parseInt(h.replace("px",""))+4;
gElements[i].style.height = nh+"px";
}
gh=gh+4;
}
if(sh>0 || gh<100) {xMenu=setTimeout("subMenu("+sCat+","+gCat+","+sh+","+gh+",'"+selection+"')",10);}
else
{
fadeOut(selection);
}
}
我已经注释掉了可以正常工作但在 IE8 中不行的脚本。我不确定 getComputedStyle 或 currentStyle 属性是否有效,但设置 style.height 属性肯定不行。
所以我的问题:
有没有办法从 IE8 中获取类似于 getElementsByClassName 的活动节点列表?
谁能建议一种将数组从 querySelectorAll 转换为元素对象数组的方法?
【问题讨论】:
标签: javascript internet-explorer-8