[英]Carrying over data from one html page to another using javascript
Hi i have a two page basic website with a submission box where you write down a name, then a second page that displays "Welcome___", however my website displays?Welcome=___, I know i need to parse a query string but I'm not sure how to您好,我有一个两页的基本网站,其中有一个提交框,您可以在其中写下一个名称,然后是显示“Welcome___”的第二页,但是我的网站显示?Welcome=___,我知道我需要解析查询字符串,但我'我不知道该怎么做
form.html表格.html
<body>
<form action="action.html" method="GET">
<input type="text" name="Welcome" />
<input type="submit" value="Submit" />
</form>
</body>
action.html行动.html
<body>
<div id="write">
<p> Welcome </p>
</div>
<script>
document.getElementById("write").innerHTML = window.location.search;
</script>
</body>
To parse
the querystring and extract from it the parameter you want the URLSearchParams interface offers useful methods to help you do what you want.要
parse
查询字符串并从中提取您想要的参数, URLSearchParams 接口提供了有用的方法来帮助您做您想做的事情。 A simple implementation might look like this.一个简单的实现可能看起来像这样。
<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.