亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定

編程練習題,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>


正在回答

4 回答

下面一個function里面少了一個參數

0 回復 有任何疑惑可以回復我~

http://img1.sycdn.imooc.com//596ed3fd00013d6010100751.jpg這樣可以顯示哦

0 回復 有任何疑惑可以回復我~

?<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 />

0 回復 有任何疑惑可以回復我~
#1

qq_XLailiaiqi_03903421

jsondata里zhangsan后面的逗號打錯了,換成英文符號試試
2017-06-03 回復 有任何疑惑可以回復我~

代碼驗證通過

http://img1.sycdn.imooc.com//58c2bb990001e25514830830.jpg

0 回復 有任何疑惑可以回復我~

舉報

0/150
提交
取消

編程練習題,each方法。求大神怎么下面的代碼不正確呢

我要回答 關注問題
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號