我正在尝试从另一个页面访问 HTML 页面的元素 ID。我见过其他解决方案,但到目前为止没有一个有效。
例如,如果这是 One.html
<input id="a" type="text"></input>
<p id="demo"></p>
我正在尝试从 Two.html 访问元素 id 'a' 以获取使用 `
输入的值var thing = document.getElementById('a').value;
document.getElementById('demo').innerHTML = "the value is" + " " + thing;
最佳答案
you can use localStorage
for example in firstpage.html you save data with
var thing = document.getElementById('a').value;
localStorage.something = thing ;
then in your seconpage.html you can use it by
document.getElementById("demo").innerHTML=localStorage.something;
关于javascript - 如何使用 JavaScript 从另一个页面访问元素 id?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40944748/