If you have no option to use server-side programming, such as PHP, you could use the query string, or GET parameters.
(如果没有使用服务器端编程(例如PHP)的选项,则可以使用查询字符串或GET参数。)
In the form, add a method="GET"
attribute:
(在表单中,添加method="GET"
属性:)
<form action="display.html" method="GET">
<input type="text" name="serialNumber" />
<input type="submit" value="Submit" />
</form>
When they submit this form, the user will be directed to an address which includes the serialNumber
value as a parameter.
(当他们提交此表单时,会将用户定向到一个地址,该地址包括serialNumber
值作为参数。)
Something like:(就像是:)
http://www.example.com/display.html?serialNumber=XYZ
You should then be able to parse the query string - which will contain the serialNumber
parameter value - from JavaScript, using the window.location.search
value:
(然后,您应该能够使用window.location.search
值从JavaScript解析查询字符串(其中将包含serialNumber
参数值):)
// from display.html
document.getElementById("write").innerHTML = window.location.search; // you will have to parse
// the query string to extract the
// parameter you need
See also JavaScript query string .
(另请参见JavaScript查询字符串 。)
The alternative is to store the values in cookies when the form is submit and read them out of the cookies again once the display.html
page loads.
(另一种方法是在提交表单时将值存储在cookie中,并在display.html
页面加载后再次从cookie中读取它们。)
See also How to use JavaScript to fill a form on another page .
(另请参见如何使用JavaScript填写另一页上的表单 。)
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…