我只是想在同一javascript文件上检索两个html页面的dom。
当我尝试检索第一个html页面的元素的dom时,它可以工作,但是第二个页面的元素使我返回undefined。我如何尝试检索第二页的元素?
firstpage.html
<p id="first">test first</p>
secondpage.html
<p id="second">test second</p>
file.js
var first = document.getElementById("first").innerHTML;
console.log(first); // will show me "test first"
var second = document.getElementById("second").innerHTML;
console.log(second); // will show me "undefined" .. :(
感谢您的帮助!