简体   繁体   English

document.getElementById访问HEAD id =“ head”时出现问题

[英]problem with document.getElementById accessing HEAD id=“head”

I am accessing head, 我正在接近头

var head = document.getElementById("head"); var head = document.getElementById(“ head”);

Works with IE, not with Firefox.. 适用于IE,不适用于Firefox。

使用此代替:

document.getElementsByTagName("head")[0]

我认为该特定标签中不允许使用属性ID。

<html>
 <head id="head">
  <script type="text/javascript" src="jquery-1.3.1.min.js" ></script>
 </head>
 <body>

 <script type="text/javascript">
  alert(document.getElementById("head"));
 </script>
 </body>
</html>

work fine in firefox. 在Firefox中工作正常。 but if you script is in the header and is runned automaticcally it could not work as the header is not fully loaded 但是如果您的脚本位于标头中并自动运行,则因为标头未完全加载而无法运行

Tested on Firefox 3 with Firebug: 在Firefox 3上使用Firebug进行了测试:

>>> document.getElementById('head')
<head id="head">

Are you sure your head element has an ID of head? 您确定head元素的ID为head吗?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM