$(function(){ var item_id = $("#item_id").val(); $('#edit-cat').modal({ "backdrop":'static' }); getList(); function getList(){ $.get( "?s=/home/member/getList", { "item_id": item_id }, function(data){ $("#show-cat").html(''); if (data.error_code == 0) { json = data.data; console.log(json); for (var i = 0; i < json.length; i++) { cat_html =''+json[i].username+' x'; $("#show-cat").append(cat_html); }; }; }, "json" ); } //保存 $("#save-cat").click(function(){ var username = $("#username").val(); $.post( "?s=/home/member/save", {"username": username ,"item_id": item_id }, function(data){ if (data.error_code == 0) { $("#username").val(''); alert("保存成功!"); }else{ alert(data.error_message); } getList(); }, "json" ); return false; }); //删除 $('#show-cat').delegate('.single-cat','click', function(){ var username = $(this).attr("data-username"); if (username) { $.post( "?s=/home/member/delete", { "username": username, "item_id" :item_id }, function(data){ if (data.error_code == 0) { alert("删除成功!"); getList(); }else{ alert("删除失败!"); } }, "json" ); } return false; }); $(".exist-cat").click(function(){ window.location.href="?s=/home/item/show&item_id="+item_id; }); });