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

时间:2012-09-10 06:44:29

标签: javascript

我正在创建一个简单的消息传递系统(用于学习目的),用户输入密码或创建一个密码,如果他们没有密码,我们的消息对应关系存储在另一个数组中的数组中。示例:您是第5个注册用户,您的密码是传递数组中的第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>

1 个答案:

答案 0 :(得分:3)

一些拼写错误;)

<!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());

  3. 工作jsfiddle

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