简体   繁体   English

如何使用JavaScript从另一个页面访问元素ID?

[英]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.

相关问题 如何使用id从javascript访问HTML元素,该html元素属于另一个html文档 - how do I access a HTML element from javascript using id,the html element belongs to another html document 通过 JavaScript 从另一个页面获取元素的 id - Get element by id from another page by JavaScript 如何访问属于另一个HTML页面的元素ID? - how to access element id which belongs to another html page? 如何使用javascript引用另一个页面元素 - how to refer another page element using javascript javascript页面元素从一个子iframe访问另一个子项 - javascript page element access from one child iframe to another child 如何使用PHP将Textnode从页面发布到具有特定ID的另一个at元素? - How to Post Textnode From a Page to Another at element With Specific Id Using PHP? 如何使用javascript从cookie访问用户ID:Rails,Devise,页面缓存 - how to access user id from cookie using javascript: Rails, Devise, Page Caching 我如何使用JavaScript从列ID到另一个页面获取价值? - how i can get value from column id to another page using javascript? 当用户单击网页时,如何从网页中删除一个元素,并使用javascript在其位置显示另一个元素 - How do i remove an element an element from my web page when a user clicks on it and display another element at it's place using javascript 从另一个页面获取Id的元素 - Get element by Id from another page
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM