求指導(dǎo)代碼那里有問題,運(yùn)行不出來啊
<!DOCTYPE html>
<html>
? ? <head>
? ? ? ? <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
? ? ? ? <title>挑戰(zhàn)題</title>
? ? ? ? <script src="https://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">?
? ? ? ? ? ?<input id="savebutton" type="button" value="savedata">
? ? ? ? ? ? <input id="showbutton" type="button" value="showbutton">?
? ? ? ? ? ? ?
? ? ? ? ? ??
? ? ? ? </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>
2018-08-16
$("#savebutton").on("click",function(){
json.push({
name:$txt.val()? ?//第一個(gè)你的push后面少了()
});
$txt.val('');? ? ?//第二個(gè)就是這里
});