为什么document.getelementbyId在Firefox中不起作用? [英] Why is document.getelementbyId not working in Firefox?
问题描述
我不知道为什么document.getElementById在Firefox中不起作用:
I can't figure out why document.getElementById is not working in Firefox:
document.getElementById("main").style.width = "100";
当我检查Firebug时,它说:
When I check in Firebug it says:
TypeError:document.getElementById("main")为空
TypeError: document.getElementById("main") is null
有人知道为什么会这样吗?
Does anybody know why this is happening?
不幸的是,"body"元素是一个不好的例子.我将其更改为ID为"main"的另一个元素.
Unfortunately, the "body" element was a bad example. I changed it to another element with an id of "main".
推荐答案
您是否已将<body>
元素的ID设置为"body":
Did you set the id of the <body>
element to "body":
<body id="body" ...>
更新:
检查以下示例是否适合您: http://jsbin.com/uyeca/edit 单击输出"选项卡以查看结果(应该是宽度为600px的DIV).
Check if the following example works for you: http://jsbin.com/uyeca/edit Click the Output tab to see the result (which should be a DIV with width 600px).
这篇关于为什么document.getelementbyId在Firefox中不起作用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!