{"id":1270,"date":"2025-01-20T23:27:16","date_gmt":"2025-01-20T15:27:16","guid":{"rendered":"http:\/\/www.chan.ink\/?p=1270"},"modified":"2025-01-21T03:17:17","modified_gmt":"2025-01-20T19:17:17","slug":"%e3%80%90web%e5%bc%80%e5%8f%91%e7%bb%84%e4%bb%b6%e4%b9%8b%e5%88%a0%e9%99%a4%e7%9a%84%e7%a1%ae%e8%ae%a4%e6%a8%a1%e6%80%81%e6%a1%86%e3%80%91","status":"publish","type":"post","link":"http:\/\/www.chan.ink\/index.php\/2025\/01\/20\/%e3%80%90web%e5%bc%80%e5%8f%91%e7%bb%84%e4%bb%b6%e4%b9%8b%e5%88%a0%e9%99%a4%e7%9a%84%e7%a1%ae%e8%ae%a4%e6%a8%a1%e6%80%81%e6%a1%86%e3%80%91\/","title":{"rendered":"\u3010Web\u5f00\u53d1\u7ec4\u4ef6\u4e4b\u5220\u9664\u7684\u786e\u8ba4\u6a21\u6001\u6846\u3011"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">1.\u5728\u5220\u9664\u7684\u5143\u7d20\u4e2d\uff0c\u52a0\u5165btn-delete\u7684\u7c7b\uff0c\u4ee5\u5b9a\u4f4d\u3002\u540c\u65f6\u6dfb\u52a0cid=\u201c{{ row.id }}\u201d<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u540c\u65f6\u518d\u628arow-id=\u201c{{ row.id}}\u201d\u653e\u5728tr\u4e2d\uff0c\u5982\u4e0b\u56fe\u6240\u793a<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"1213\" height=\"381\" src=\"http:\/\/www.chan.ink\/wp-content\/uploads\/2025\/01\/1737386592950.png\" alt=\"\" class=\"wp-image-1271\"\/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">2.\u628a\u5220\u9664\u65f6\u5f39\u51fa\u7684\u6a21\u6001\u6846\u4ee3\u7801\u7247\u6bb5\u5bfc\u5165\uff0c\u5982\u4e0b\u56fe\u6240\u793a<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"1270\" height=\"687\" src=\"http:\/\/www.chan.ink\/wp-content\/uploads\/2025\/01\/1737386645844.png\" alt=\"\" class=\"wp-image-1272\"\/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">\u5b8c\u6574\u7684\u4ee3\u7801\u5982\u4e0b\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;div class=\"modal fade\" id=\"deleteModal\" tabindex=\"-1\" role=\"dialog\" aria-labelledby=\"myModalLabel\">\n    &lt;div class=\"modal-dialog\" role=\"document\">\n        &lt;div class=\"alert alert-danger alert-dismissible fade in\" role=\"alert\">\n            &lt;h4>\u662f\u5426\u786e\u5b9a\u8981\u5220\u9664\uff1f&lt;\/h4>\n            &lt;p>Change this and that and try again. Duis mollis, est non commodo luctus, nisi erat porttitor ligula,\n                eget lacinia odio sem nec elit. Cras mattis consectetur purus sit amet fermentum.&lt;\/p>\n            &lt;p>\n                &lt;button type=\"button\" class=\"btn btn-danger\" id=\"btnConfirmDelete\">\u786e\u5b9a&lt;\/button>\n                &lt;button type=\"button\" class=\"btn btn-default\" id=\"btnCancelDelete\">\u53d6\u6d88&lt;\/button>\n                &lt;span style=\"color: red\" id=\"deleteError\">&lt;\/span>\n            &lt;\/p>\n        &lt;\/div>\n    &lt;\/div>\n&lt;\/div><\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">3.\u628a\u76f8\u5bf9\u5e94\u7684JS\u4ee3\u7801\u5f15\u5165\uff0c\u4ee5\u53ca\u8bbe\u7f6e\u5168\u5c40\u53d8\u91cf\uff0c\u5982\u4e0b\u56fe\u6240\u793a<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"784\" height=\"421\" src=\"http:\/\/www.chan.ink\/wp-content\/uploads\/2025\/01\/1737386745269.png\" alt=\"\" class=\"wp-image-1273\"\/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">\u8be6\u7ec6\u7684JS\u4ee3\u7801\u5982\u4e0b\u56fe\u6240\u793a\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>$(function (){\n            bindDeleteEvent();\n            bindConfirmDeleteEvent();\n        });\n\n        function bindDeleteEvent(){\n            $('.btn-delete').click(function (){\n                $(\"#deleteError\").empty();\n\n                $('#deleteModal').modal('show');\n                var cid = $(this).attr('cid');\n                DELETE_ID = cid;\n\n            });\n\n\n            $('#btnCancelDelete').click(function (){\n               $('#deleteModal').modal('hide');\n            });\n        }\n\n        function bindConfirmDeleteEvent(){\n            $('#btnConfirmDelete').click(function (){\n                console.log('\u786e\u8ba4\u5220\u9664\uff1a',DELETE_ID);\n\n                \/\/ajax\u53d1\u9001\u8bf7\u6c42\n                $.ajax({\n                    url:DELETE_URL,\n                    type:'GET',\n                    data: {cid:DELETE_ID},\n                    dataType: 'JSON',\n                    success:function (res){\n                        if(res.status){\n                            \/\/\u5220\u9664\u6210\u529f\n                            \/\/\u65b9\u5f0f\u4e00: \u4f5c\u9875\u9762\u7684\u5237\u65b0\n                            \/\/location.reload();\n\n                            \/\/\u65b9\u5f0f\u4e8c: \u5f53\u524d\u6570\u636e\u5728\u9875\u9762\u4e2d\u5220\u9664\n                            $(\"tr&#91;row-id='\"+ DELETE_ID + \"']\").remove();\n                            $('#deleteModal').modal('hide');\n\n                        }else{\n                            \/\/\u5220\u9664\u5931\u8d25\n                            $('#deleteError').text(res.detail);\n                        }\n                    }\n                })\n            });\n        }<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">4.\u5728django\u7684\u540e\u7aef\u89c6\u56fe\u51fd\u6570\u4e2d\uff0c\u505a\u5bf9\u5e94\u7684\u64cd\u4f5c<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"705\" height=\"249\" src=\"http:\/\/www.chan.ink\/wp-content\/uploads\/2025\/01\/1737386824711.png\" alt=\"\" class=\"wp-image-1274\"\/><\/figure>\n","protected":false},"excerpt":{"rendered":"<p>1.\u5728\u5220\u9664\u7684\u5143\u7d20\u4e2d\uff0c\u52a0\u5165btn-delete\u7684\u7c7b\uff0c\u4ee5\u5b9a\u4f4d\u3002\u540c\u65f6\u6dfb\u52a0cid=\u201c{{ row.id }}\u201d \u540c\u65f6\u518d [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[9],"tags":[],"class_list":["post-1270","post","type-post","status-publish","format-standard","hentry","category-9"],"_links":{"self":[{"href":"http:\/\/www.chan.ink\/index.php\/wp-json\/wp\/v2\/posts\/1270","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/www.chan.ink\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.chan.ink\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.chan.ink\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.chan.ink\/index.php\/wp-json\/wp\/v2\/comments?post=1270"}],"version-history":[{"count":1,"href":"http:\/\/www.chan.ink\/index.php\/wp-json\/wp\/v2\/posts\/1270\/revisions"}],"predecessor-version":[{"id":1275,"href":"http:\/\/www.chan.ink\/index.php\/wp-json\/wp\/v2\/posts\/1270\/revisions\/1275"}],"wp:attachment":[{"href":"http:\/\/www.chan.ink\/index.php\/wp-json\/wp\/v2\/media?parent=1270"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.chan.ink\/index.php\/wp-json\/wp\/v2\/categories?post=1270"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.chan.ink\/index.php\/wp-json\/wp\/v2\/tags?post=1270"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}