将表单数据传递给另一个HTML页面 [英] passing form data to another HTML page
问题描述
我有两个HTML页面:form.html和display.html。在form.html中,有一个表单:
< form action =display.html>
< input type =textname =serialNumber/>
< input type =submitvalue =Submit/>
< / form>
表单数据被发送到display.html。我想在display.html中显示和使用表单数据 serialNumber
,如下所示:
<身体GT;
< div id =write>
< p>序列号是:< / p>
< / div>
< script>
function show(){
document.getElementById(write)。innerHTML = serialNumber;
}
< / script>
< / body>
那么如何传递 serialNumber
变量从form.html到display.html,以便display.html中的上述代码将显示序列号,并且JavaScript函数show()从第一个HTML中获取 serialNumber
。如果你没有选择使用服务器端编程,比如PHP,你可以使用查询字符串或者GET参数。
在表单中,添加一个 method =GET
属性:
< form action =display.htmlmethod =GET>
< input type =textname =serialNumber/>
< input type =submitvalue =Submit/>
< / form>
当他们提交这个表单时,用户将被引导到一个地址,其中包含 serialNumber
值作为参数。例如:
http://www.example.com/display.html?serialNumber=XYZ
code>
然后,您应该能够解析查询字符串 - 它将包含 serialNumber
参数值 - 来自JavaScript,使用 window.location.search
值:
// from display.html
document.getElementById(write)。innerHTML = window.location.search; //你将必须解析
//查询字符串来提取你需要的
//参数
另见 JavaScript查询字符串。
另一种方法是在表单提交时将值存储在cookie中,并在 I have two HTML pages: form.html and display.html. In form.html, there is a form: The form data is sent to display.html. I want to display and use the form data So how can I pass the If you have no option to use server-side programming, such as PHP, you could use the query string, or GET parameters. In the form, add a When they submit this form, the user will be directed to an address which includes the You should then be able to parse the query string - which will contain the See also JavaScript query string. The alternative is to store the values in cookies when the form is submit and read them out of the cookies again once the See also How to use JavaScript to fill a form on another page. 这篇关于将表单数据传递给另一个HTML页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋! display.html $ b
<form action="display.html">
<input type="text" name="serialNumber" />
<input type="submit" value="Submit" />
</form>
serialNumber
in display.html, as shown below:<body>
<div id="write">
<p>The serial number is: </p>
</div>
<script>
function show() {
document.getElementById("write").innerHTML = serialNumber;
}
</script>
</body>
serialNumber
variable from form.html to display.html so that the above code in display.html will show the serial number and the JavaScript function show() gets the serialNumber
from the first HTML?method="GET"
attribute:<form action="display.html" method="GET">
<input type="text" name="serialNumber" />
<input type="submit" value="Submit" />
</form>
serialNumber
value as a parameter. Something like:http://www.example.com/display.html?serialNumber=XYZ
serialNumber
parameter value - from JavaScript, using the window.location.search
value:// from display.html
document.getElementById("write").innerHTML = window.location.search; // you will have to parse
// the query string to extract the
// parameter you need
display.html
page loads.