Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/71.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript &引用;SCRIPT5002函数应为“;IE中的错误_Javascript_Jquery_Html_Iframe - Fatal编程技术网

Javascript &引用;SCRIPT5002函数应为“;IE中的错误

Javascript &引用;SCRIPT5002函数应为“;IE中的错误,javascript,jquery,html,iframe,Javascript,Jquery,Html,Iframe,我面临着一个问题,并且犯了这样的错误 internet explorer 7-9中应为“SCRIPT5002函数”。 这是我的代码: var myDiv = document.getElementById("divId"); //this line gives me "SCRIPT5002 function expected" error. myDiv.style.cssText("position:absolute;z-index:999"); myDiv.appendChild(

我面临着一个问题,并且犯了这样的错误 internet explorer 7-9中应为“SCRIPT5002函数”。 这是我的代码:

 var myDiv = document.getElementById("divId"); //this line gives me "SCRIPT5002 function expected" error.

 myDiv.style.cssText("position:absolute;z-index:999");
myDiv.appendChild(
        JavaScriptCode);

那么如何解决这个问题呢?

问题应该在第二行:

myDiv.style.cssText("position:absolute;z-index:999");
所以这样称呼它:

myDiv.style.cssText = "position:absolute;z-index:999";
或者(我认为更好的方法,因为它更清晰):


我也是在尝试检查变量是否是元素时得到这个的

"notAnElement" instanceof Element
它总是抛出预期的
函数
错误

document.createElement("div") instanceof Element
成功计算为
true


我还没有实现它,但我的解决方案是使用try/catch块。

您想实现什么?尤其是“附加儿童”部分我认为错误不在第一行。脚本是如何嵌入到您的页面中的?这是唯一的脚本吗?是的,但我不认为这会引发“函数预期错误”。@Bergi确实如此。看看在控制台打开的情况下使用IE。
document.createElement("div") instanceof Element