[英]How to access element id from another page using JavaScript?
I am trying to access an element id of an HTML page from another page. 我正在尝试从另一个页面访问HTML页面的元素ID。 I have seen other solutions but none have worked so far.
我看到了其他解决方案,但到目前为止都没有奏效。
For example, if this is One.html 例如,如果这是One.html
<input id="a" type="text"></input>
<p id="demo"></p>
I am trying to access the element id 'a' from Two.html to get the value that has been inputted using ` 我正在尝试从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;
sorry I don't have enough reputation to leave this as a comment but just a heads up, input tags are standalone tags. 抱歉,我没有足够的声誉来将此留为评论,但请注意,输入标签是独立标签。
Example:
<body>
<input type="text" id="a" />
</body>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.