为什么点击保存没有反应,alert里面的内容都没弹出来

来源:1-11 编程练习

慕粉3311989

2018-09-17 16:14

<!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>

    </head>

    <body>

        <input id="username" type="text" name="" />

        <input id="age" type="text" name="" />

        <input id="save" type="button" value="保存"/>

        <input id="show" type="button" value="显示"/>

        <ul></ul>

        <script type="text/javascript">

            $(function(){

                var json=[];

                $("#save").bind("click",function(){

                    alert("保存");

                    json.push({

                        

                        "username":$("#username").val(),

                        "age":$("#age").val()

                    });

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

                    $("#age").val("");

                });

                $("#show").bind("click",function(){

                    $.each(json,function(i){

                        $("ul").append("<li>"+json[i].username+json[i].age"</li><br>")

                    })

                });

            })

        </script>

    </body>

</html>


写回答 关注

1回答

  • 薄荷美美哒
    2018-09-17 20:46:15

    <!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>


        </head>


        <body>


            <input id="username" type="text" name="" />


            <input id="age" type="text" name="" />


            <input id="save" type="button" value="保存"/>


            <input id="show" type="button" value="显示"/>


            <ul></ul>


            <script type="text/javascript">


                $(function(){


                    var json=[];


                    $("#save").bind("click",function(){


                        alert("保存");


                        json.push({


                            


                            "username":$("#username").val(),


                            "age":$("#age").val()


                        });


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


                        $("#age").val("");


                    });


                    $("#show").bind("click",function(){


                        $.each(json,function(i){


                            $("ul").append("<li>"+json[i].username+json[i].age+"</li><br>");


                        })


                    });


                })


            </script>


        </body>


    </html>

     $("ul").append("<li>"+json[i].username+json[i].age+"</li><br>");少了一个分号,一个加号


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

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

69095 学习 · 400 问题

查看课程

相似问题