[英]Passing JavaScript data value between 2 HTML pages
I'm trying to pass a value from one HTML document to the other, and this works, but when it's printing out the value, it's adding the name tag text=
in front of it.我正在尝试将一个 HTML 文档中的值传递给另一个文档,这是可行的,但是当它打印出该值时,它会在其前面添加名称标签text=
。 Is there a way to get rid of the text=
and just showing the entered value?有没有办法摆脱text=
并只显示输入的值?
here is the form of the first page: pageOne.html
这是第一页的形式: pageOne.html
<form action="pageTwo.html" method="get">
<input type="text" name="text" />
<input type="submit" value="submit" />
</form>
and here the script of the second page: pageTwo.html
这里是第二页的脚本: pageTwo.html
<script>
var queryString = decodeURIComponent(window.location.search);
queryString = queryString.substring(1);
var queries = queryString.split("&");
document.write(queries[0]);
</script>
You can use URLSearchParams
.您可以使用URLSearchParams
。
GET /pageTwo.html?text=hello
<script>
var urlParams = new URLSearchParams(window.location.search)
var textValue = urlParams.get('text')
console.log(textValue)
</script>
Result: hello
结果: hello
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.