为什么我的代码按保存反而跳到慕课网了...??

来源:1-11 编程练习

Taehong

2018-09-20 10:08

<!DOCTYPE html>

<html>

    <head>

        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

        <script src="https://libs.baidu.com/jquery/1.9.0/jquery.js" type="text/javascript"></script>

        <title>挑战题</title>

        <style>

            .table p

            {

                display:inline;

                margin-right:10px;

            }

            #save_info,#show_info

            {

                margin-top:30px;

                margin-left:30px;

            }

        </style>

    </head>

    <body>

        <form action="#" method="get">

          <div class="table">

            <p>username:</p>

            <input id="username" type="text" placeholder="请输入账号"/>

            <br/>

            <p>password:</p>

            <input id="password" type="text" placeholder="请输入密码"/>

            <br/>

            <button id="save_info">Save</button>

            <button id="show_info">Show</button>

          </div>

          <ul id="perform"></ul>

        </form>

    <script type="text/javascript">

        var json = [];

        

        $("save_info").on("click",function(){

            json.push({

                username:$("username").val();

                password:$("password").val();

            })

            $("username").val('')

            $("password").val('')

            $("this").attr("disabled","true");

            alert("save success");

        });

        

        $("show_info").on("click",function(){

            $.each(json,function(index,person){

                $("#perform").appendChild("<li>" + "username:" +json[index].username + "password:" + json[index].password + "</li>")

            }

        })

    </script>

    </body>

</html>


写回答 关注

1回答

  • 慕粉4019140
    2018-10-20 18:25:26

    兄弟,你的代码一堆语法错误,有的id选择器怎么连#都不加了,你把代码代码先丢开发工具上排除语法错误吧........

jQuery基础(五)一Ajax应用与常用插件

如何用jquery实现ajax应用,加入学习,有效提高前端开发速度

69095 学习 · 400 问题

查看课程

相似问题