getElementById在Chrome中运行但不在Firefox中运行?

时间:2016-03-01 18:30:00

标签: javascript html google-chrome firefox

嗨,

我是网络开发人员的新手,所以我相信很多人会在这里面对。

标记:

<DOCTYPE html>
<head>
    <meta charset="utf-8">
    <title>this is an example</title>
    <script type="text/javascript" src="path/to/script.js"></script>
</head>

<body>
    <div id="id1">Some text here</div>
    <div id="id2">Some other text here</div>

</body>

JS:

window.onload = function() {
    var id1 = document.getElementById("id1");
    var id2 = document.getElementById("id2");
    console.log(id1);
    console.log(id2);
}

在Chrome中,我得到了我期望打印到控制台的内容。在Firefox中我得到null。 ??

0 个答案:

没有答案
相关问题