Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/418.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/85.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript webbrowser中的本地存储_Javascript_Jquery_Html_Local Storage - Fatal编程技术网

Javascript webbrowser中的本地存储

Javascript webbrowser中的本地存储,javascript,jquery,html,local-storage,Javascript,Jquery,Html,Local Storage,我有一个输入类型的文本框值是要存储在本地存储按钮提交后 <html> <body action="Servlet.do" > <input type="text" name="a"/> <button type="submit"></button> </body> </html> 提交按钮后如何在localstorage中存储?单击提交按钮的功能后,请执行以下代码,使用键“a”将文本框值存储在localst

我有一个输入类型的文本框值是要存储在本地存储按钮提交后

<html>
<body action="Servlet.do" >
<input type="text" name="a"/>
<button type="submit"></button>
</body>
</html>


提交按钮后如何在localstorage中存储?

单击提交按钮的功能后,请执行以下代码,使用键“a”将文本框值存储在localstorage中

请查看下面的代码片段以了解更多信息

HTML

<html>
  <body action="Servlet.do" >
    <input type="text" name="a"/>
    <button type="submit" onclick="storeVal();">Submit</button>
  </body>
</html>

您可以从此列表中检查目标浏览器是否支持localstorage。然后,您可以使用localStorage.setItem设置一个值,并使用localStorage.getItem检索该值。

您也可以这样做:

$('input').val(localStorage.inputvalue)
本地存储用作键/值,其中我使用[inputValue]作为键

jQuery

要从LocalSorage获取值,请执行以下操作:

$('input').val(localStorage.inputvalue)

单击按钮并提交表单。您需要添加一个事件侦听器
单击
,然后使用localstorage执行写入逻辑。
localStorage.inputvalue = $('input').val()
$('input').val(localStorage.inputvalue)