第12章
}) then(r => rjn()) then(res => { if (!resok) { showsg(ressg || '操作失败', true); return; } showsg(ressg || (isedit ? '修改成功' : '添加成功'), false); resetfor(); loadlist(); }) catch(() => showsg('请求失败', true)); }); function resetfor() { editidvae = ''; editdoavae = ''; edittitlevae = ''; fortitletextntent = '新增'; btncancelstyledispy = 'none'; } listeladdeventlistener('click', function(e) { var id = etarttattribute('data-id'); if (!id) return; if (etartcsslistntas('edit-btn')) { fetch(api + '?action=t&id=' + id) then(r => rjn()) then(res => { if (!resok) { showsg(ressg || '获取失败', true); return; } var d = resdata; editidvae = did; editdoavae = ddoa; edittitlevae = dtitle; fortitletextntent = '修改'; btncancelstyledispy = 'le-block'; }); } else if (etartcsslistntas('del-btn')) { if (!nfir('确定删除 id=' + id + ' 吗?')) return; var fd = new fordata(); fdappend('action', 'delete'); fdappend('id', id); fetch(api, { thod: 'post', body: fd }) then(r => rjn()) then(res => { if (!resok) { showsg(ressg || '删除失败', true); return; } showsg('删除成功', false); loadlist(); }); } }); btncanceladdeventlistener('click', resetfor); loadlist();