一、Ajax
<tr id='tr_<{$row.sn}>' data-sn='<{$row.sn}>'>td
<td class="text-left event_title"> <{$row.title}> </td>
<{* 刪除 rende *}> <link rel="stylesheet" href="<{xoAppUrl modules/tadtools/sweet-alert/sweet-alert.css}>" type="text/css" /> <script src="<{xoAppUrl modules/tadtools/sweet-alert/sweet-alert.js}>" type="text/javascript"></script> <script type="text/javascript"> $(function() { //每行的删除操作注册脚本事件 $(".btnDel").bind("click", function(){ var vbtnDel=$(this);//得到点击的按钮对象 var vTr=vbtnDel.parents("tr");//得到父tr对象; var sn=vTr.attr("data-sn");//取得 sn var title=vTr.find(".event_title").html();//取得 title //警告視窗 swal({ title: '<{$smarty.const._TAD_DEL_CONFIRM_TITLE}>', text: title, type: 'warning', showCancelButton: 1, confirmButtonColor: '#DD6B55', confirmButtonText: '<{$smarty.const._TAD_DEL_CONFIRM_BTN}>', closeOnConfirm: false , allowOutsideClick: true }, function(){ //確定,執行 $.post('<{$SCRIPT_NAME}>', {op:"opDelete",sn:sn}, function(msg){ //console.log(msg); if(msg==1){ vTr.remove();//刪除 swal("刪除完成!", title, "success"); }else{ swal("刪除失敗!", title, "error"); } }); }); }); //给删除按钮注册js脚本 }); </script>
按鈕(b4)
<button class="btn btn-danger btn-sm btnDel"><{$smarty.const._DELETE}></button>
按鈕(b3)
<button class="btn btn-danger btn-xs btnDel"><{$smarty.const._DELETE}></button>
case "opDelete"://刪除資料 #ajax必須關除錯 ugm_module_debug_mode(0);//強制關除錯 echo opDelete(); XoopsCache::clear(); exit;
######################################## # 3.刪除資料ajax ######################################## function opDelete() { global $xoopsDB,$tbl; $sn = intval($_REQUEST['sn']); if (!$sn) { return false; } $sql = "delete from " . $xoopsDB->prefix($tbl) . " where sn='{$sn}'"; //die($sql); #ajax除錯 "/uploads/debug/$fileName" //ajaxDebug($sql,"opDelete"); if($xoopsDB->queryF($sql)){ return true; } return false; }
二、轉向