edit.js 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. $(function(){
  2. var item_id = $("#item_id").val();
  3. $('#edit-cat').modal({
  4. "backdrop":'static'
  5. });
  6. getList();
  7. function getList(){
  8. $.get(
  9. "?s=/home/member/getList",
  10. { "item_id": item_id },
  11. function(data){
  12. $("#show-cat").html('');
  13. if (data.error_code == 0) {
  14. json = data.data;
  15. console.log(json);
  16. for (var i = 0; i < json.length; i++) {
  17. cat_html ='<a class="badge badge-important single-cat" data-username="'+json[i].username+'" >'+json[i].username+'&nbsp;x</a>';
  18. $("#show-cat").append(cat_html);
  19. };
  20. };
  21. },
  22. "json"
  23. );
  24. }
  25. //保存
  26. $("#save-cat").click(function(){
  27. var username = $("#username").val();
  28. $.post(
  29. "?s=/home/member/save",
  30. {"username": username ,"item_id": item_id },
  31. function(data){
  32. if (data.error_code == 0) {
  33. $("#username").val('');
  34. alert("保存成功!");
  35. }else{
  36. alert(data.error_message);
  37. }
  38. getList();
  39. },
  40. "json"
  41. );
  42. return false;
  43. });
  44. //删除
  45. $('#show-cat').delegate('.single-cat','click', function(){
  46. var username = $(this).attr("data-username");
  47. if (username) {
  48. $.post(
  49. "?s=/home/member/delete",
  50. { "username": username, "item_id" :item_id },
  51. function(data){
  52. if (data.error_code == 0) {
  53. alert("删除成功!");
  54. getList();
  55. }else{
  56. alert("删除失败!");
  57. }
  58. },
  59. "json"
  60. );
  61. }
  62. return false;
  63. });
  64. $(".exist-cat").click(function(){
  65. window.location.href="?s=/home/item/show&item_id="+item_id;
  66. });
  67. });