編程練習題,each方法。求大神怎么下面的代碼不正確呢
<html>
? ? <head>
? ? ? ? <title>挑戰題</title>
? ? ? ? <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
? ? ? ? <script src="http://libs.baidu.com/jquery/1.9.0/jquery.js" type="text/javascript"></script>
? ? ? ? <style>
? ? ? ? ? ? ul {margin: 0; padding: 0;}
? ? ? ? ? ? li { list-style: none;}
? ? ? ? ? ? input.text { padding-left: 4px; outline: none;}
? ? ? ? </style>
? ? </head>
? ? <body>
<form action="#" method="get">
? ? <input id="text" class="text" type="text" name="UserName" placeholder="請輸入姓名">
? ? <input id="SaveButton" type="button" value="Save Data">
? ? <input id="ShowButton" type="button" value="Show Data">
? ? </form>
? ? ? <ul></ul>
<script>
? ? var $txt=$("#text");
? ? var json=[];
? ? $('#SaveButton').on('click',function () {
? ? ? ? json.push({name: $txt.val()})
? ? });
? ? $("#ShowButton").on("click",function () {
? ? ? ? $.each(json,function (index) {
? ? ? ? ? ? $("ul").append("<li>"+json[index].name+"</li>")
? ? ? ? })
? ? })
? ? ? ??
? ? ? ? </script>
? ? </body>
</html>
2017-03-23
下面一個function里面少了一個參數
2017-07-19
2017-04-24
?<body>
??????? <ul id="result"></ul>
??????? <br>
??????? <button>加載</button>
?????? ?
??????? <script>
??????? var Jsondata = [
??????????????? {"score":96, "name":"zhangsan"},
??????????????? {"score":95, "name":"lisi"},
??????????????? {"score":89, "name":"wangwu"},
??????????????? {"score":90, "name":"zhangliu"}
??????? ];
?????? ?
??????? $("button").on('click',function(){
??????????? $.each(Jsondata,function(index,obj){
??????????????? $("#result").append("<li>" + obj.name + ":" + obj.score +"</li>");
??????????? });
??????? });
??????? </script>
?</body>
我這個怎么不行?。?br />
2017-03-10
代碼驗證通過