![](/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.