![](/img/trans.png)
[英]how to transfer data from one html page to another using javascript
[英]Carrying over data from one html page to another using javascript
您好,我有一個兩頁的基本網站,其中有一個提交框,您可以在其中寫下一個名稱,然后是顯示“Welcome___”的第二頁,但是我的網站顯示?Welcome=___,我知道我需要解析查詢字符串,但我'我不知道該怎么做
表格.html
<body>
<form action="action.html" method="GET">
<input type="text" name="Welcome" />
<input type="submit" value="Submit" />
</form>
</body>
行動.html
<body>
<div id="write">
<p> Welcome </p>
</div>
<script>
document.getElementById("write").innerHTML = window.location.search;
</script>
</body>
要parse
查詢字符串並從中提取您想要的參數, URLSearchParams 接口提供了有用的方法來幫助您做您想做的事情。 一個簡單的實現可能看起來像這樣。
<form action='action.html' method='GET'>
<input type='text' name='Welcome' />
<input type='submit' />
</form>
<div id='write'>
<p>Welcome </p>
</div>
<script>
let args=new URLSearchParams( location.search );
if( args.has('Welcome') ){
document.getElementById('write').querySelector('p').textContent += args.get('Welcome');
}
</script>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.