简体   繁体   English

使用 javascript 中的输入“type=text”元素将值从一页传递到另一页

[英]passing value from one page to another using input "type=text" element in javascript

page name 3.html页面名称 3.html

<html>
    <body>
<form action="4.html" onSubmit="cal()">
    <table>
        <tr>
            <td><input type="text" id="sen"/></td>
            <td><input type="submit" value="tap me"/></td>
        </tr>
    </table>
</form>
</body>
<script>
    function call(){
        var a = document.getElementById("sen").value;
        localStorage.setItem("a",a);
    }
</script>
</html>

page name 4.html页面名称 4.html

<html>
    <body>
        <table>
    <tr>
        <td><p id="r"></p></td>
    </tr>
</table>
</body>
<script>
    var get = localStorage.getItem('sen');
    alert(get);
    document.getElementById("r").innerHTML=get;
</script>
</html>

i am trying to pass value from 3.html to 4.html but it is passing null value.我正在尝试将值从 3.html 传递到 4.html 但它正在传递 null 值。 why is it passing the null value?为什么要传递 null 值? how to resolve this error?如何解决这个错误?

Looks like you have an error when calling the function onSubmit=" cal() "看起来你在调用 function onSubmit=" cal() " 时出错

The defined function name is call()定义的function名称为call()

Apart that you are trying to set the session with key a and retrieve it with key seen .除此之外,您正在尝试使用密钥a设置 session 并使用密钥seen检索它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM