简体   繁体   English

使用 javascript 将数据从一个 html 页面转移到另一个页面

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

相关问题 如何使用javascript将数据从一个html页面传输到另一页面 - how to transfer data from one html page to another using javascript 如何仅使用JavaScript将表单数据从一个HTML页面传递到另一HTML页面? - How do I pass form data from one HTML page to another HTML page using ONLY javascript? 从 javascript 数据集中删除一行并将其转移到另一个数据集中? - Removing a row from a javascript dataset and carrying it over into another dataset? 如何使用Phonegap中的JavaScript将数据从一个html传递到另一个html页面? - How to pass the data from one html to another html page using JavaScript in Phonegap? 使用cookie,javascript和html将数据从一个页面呈现到另一个页面 - Present the data from one page to another page using cookies ,javascript and html 如何使用JavaScript将HTML FORM数据从一个页面发送到另一个页面 - How to send HTML FORM data from one page to another using JavaScript 如何使用JavaScript将列表组之类的数据从一个HTML页面传递到另一HTML页面? - How can I pass data like list group from one html page to another using JavaScript? 如何使用 JavaScript 将数据从一个 HTML 页面传递到另一个页面 - How can i pass data from one HTML page to another using JavaScript 从一个php文件导航到另一个承载数据的数组 - Navigate from one php file to another carrying array of data 将表单数据从一种表单传送到另一种表单? 这可能吗? - Carrying Form data from one form to another form? Is this possible?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM