4

提交表单时,如何将值从表单保存到 sessionStorage?

像这样的东西?

        <form id="myForm" method="get" action="lista.html" rel="external" data-ajax="false" >

        <label for="autonumero"> Anna autonumero </label>
        <input type='tel' name="autonumero" data-corners="false"/>


        <input type="submit" onclick="saveData()" value="OK" data-theme="a" data-corners="false" />



        <script> function savedata()
{ var input = document.getElementById("autonumero");
sessionStorage.setItem("autonumero", input.value); 
</script> 






        </form>

表单也需要提交,因此仅保存值是不够的

4

3 回答 3

1

尝试:

<input type="submit" onclick="return saveData();" value="OK" data-theme="a" data-corners="false" />
<script type="text/javascript"> 
function savedata() { 
  var input = document.getElementById("autonumero");
  sessionStorage.setItem("autonumero", input.value);
  return true;
} 
</script> 
于 2012-05-02T12:18:48.593 回答
1

尝试设置输入 id id="autonumero"

<input id="autonumero" type="submit" onclick="return saveData();" value="OK" data-theme="a" data-corners="false" />
于 2015-08-02T23:27:23.577 回答
0

设置id="autonumero"为输入字段:

<input type='tel' id="autonumero" name="autonumero" data-corners="false"/>
于 2021-04-30T12:13:49.973 回答