javascript - 为什么 <p> 没有被插入到我的 html 中?

标签 javascript

我正在创建一个简单的消息传递系统(用于学习目的),用户输入密码或创建一个(如果没有密码),并且我们的消息对应存储在另一个数组中的一个数组中。示例:您是第 5 个注册的用户,您的密码是 pass 数组中的第 5 项,而我们的对应项是 logNum 数组中的第 5 项。

我想知道是否可以使用本地存储,以便用户可以关闭浏览器并仍然保存我们的通信以及如何修改日志。但到目前为止,我底部的确认段落甚至没有插入到文档中。

我非常感谢任何建议。

<!DOCTYPE HTML> 
    <html>     
        <head>             
            <title>waGwan?</title>     
            <meta charset="utf-8"/>
            <link rel=stylesheet href=comm.css></link>       
        </head>     
            <body>                              
                <section>
                    <p>enter or create passcode: <input type=text id=passcode></p>
                    <input type=button id="button" value="send">
                </section>
                <section id="log"></section>
                <script type="text/javascript">
                    var pass[];
                    var logNum=[];
                    document.getElementById("button").onclick=checkPass;
                    function checkPass(){
                        for(i=0;i<pass.length;i++){
                            //if passcode already exists exit
                            if(document.getElementById("passcode").value==pass[i]){
                                break;
                            }
                            //if passcode doesn't equal last existing passcode the passcode is added to the pass array and an array with name passcode is added to the logNum array
                            else if(document.getElementById("passcode").value!==pass[pass.length-1]){
                                pass.push(document.getElementById("passcode").value)
                                logNum.push(var document.getElementById("passcode").value.toString()[]);
                            }
                        }
                        //adds "Works!" to document
                        document.getElementById("log").innerHTML="<p>Works!</p>";
                    }
                </script>
            </body> 
    </html>

最佳答案

有些错别字;)

<!DOCTYPE HTML> 
    <html>     
        <head>             
            <title>waGwan?</title>     
            <meta charset="utf-8"/>
            <link rel=stylesheet href=comm.css></link>       
        </head>     
            <body>                              
                <section>
                    <p>enter or create passcode: <input type=text id=passcode></p>
                    <input type=button id="button" value="send">
                </section>
                <section id="log"></section>
                <script type="text/javascript">
                    var pass=[]; << here
                    var logNum=[];
                    document.getElementById("button").onclick=checkPass;
                    function checkPass(){
                        for(i=0;i<pass.length;i++){
                            //checking if passcode already exists
                            if(document.getElementById("passcode").value==pass[i]){
                                break;
                            }
                            //if passcode doesn't equal last existing passcode the passcode is added to the pass array and an array with name passcode is added to the logNum array
                            else if(document.getElementById("passcode").value!==pass[pass.length-1]){
                                pass.push(document.getElementById("passcode").value)
                                logNum.push(document.getElementById("passcode").value.toString());<< here
                            }
                        }
                        //adds "Works!" to document
                        document.getElementById("log").innerHTML="<p>Works!</p>";
                    }
                </script>
            </body> 
    </html>
  1. var pass = [];

  2. logNum.push(document.getElementById("passcode").value.toString());

工作中jsfiddle

尝试使用适用于 FireFox 的 Firebug 或其他适用于您的浏览器的开发人员工具。

关于javascript - 为什么 <p> 没有被插入到我的 html 中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12346541/

相关文章:

javascript - 检测覆盖 iframe 的系统窗口

javascript - 单击 div 不起作用

javascript - iframe 的 contentDocument

javascript - 使用异或变量计算

javascript - 从 jQuery 选择器中过滤元素

javascript - Parse.com/Javascript - 将用户 objectid 字符串保存为用户指针

javascript - 如何使用 Enjo 2.0 Web 服务对象

javascript - 需要有关 javascript 和 Visual C++ 通信的帮助,反之亦然

java - 什么类转换为 GWT 中的 java 脚本?

javascript - Highcharts - 通过单击单选按钮动态更改图表类型