我想将表单值从一个 html 页面传递到另一个 html 页面。
我想知道是否可以在不使用服务器端代码的情况下在 html 页面之间传递值。
如果没有,我该如何传递值? (我宁愿不使用服务器端...)
这是我的一些项目代码:
第一个 HTML 页面
<form id="myForm" method="post" action="secondHTMLPage URL">
<input type="hidden" id="UserID" name="UserID" value="12345">
</form>
<script type="text/javascript">
$("#myForm").submit();
</script>
第二个 HTML 页面
<script type="text/javascript">
// In here, I want to retrieve my $("#myForm")'s data from First Page.
</script>
最佳答案
你可以试试Window.sessionStorage或 Window.localStorage .
The read-only
localStorage
property allows you to access a Storage object for the Document's origin; the stored data is saved across browser sessions.
localStorage
is similar tosessionStorage
, except that while data stored inlocalStorage
has no expiration time, data stored insessionStorage
gets cleared when the page session ends — that is, when the page is closed.
在一页中设置值
localStorage.setItem('myCat', 'Tom');
//using sessionStorage
//sessionStorage.setItem('myCat', 'Tom');
获取其他页面的值
var cat = localStorage.getItem('myCat');
//using sessionStorage
//var cat = sessionStorage.getItem('myCat');
关于javascript - 将值从一个页面传递到另一个页面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58759146/