我正面临着一个问题,并且在internet explorer 7-9中得到了类似"SCRIPT5002 function expected“的错误。这是我的代码:
var myDiv = document.getElementById("divId"); //this line gives me "SCRIPT5002 function expected" error.
myDiv.style.cssText("position:absolute;z-index:999");
myDiv.appendChild(
JavaScriptCode);那么如何解决这个问题呢?
发布于 2013-02-05 16:46:47
问题应该在第二行:
myDiv.style.cssText("position:absolute;z-index:999");cssText is not a function, but a property.,所以这样叫它:
myDiv.style.cssText = "position:absolute;z-index:999";或者(在我看来,更好的方法,因为它更清晰):
myDiv.style.position = 'absolute';
myDiv.style.zIndex = 999;发布于 2013-08-29 08:57:25
我还得到了这个,试图检查一个变量是否是一个元素。
"notAnElement" instanceof Element并且它总是抛出function expected错误。
document.createElement("div") instanceof Element成功求值为true
我还没有实现它,但是我的解决方案是使用try/catch块。
https://stackoverflow.com/questions/14703239
复制相似问题