layui删除弹窗确认-删除弹出确认
Js代码如下: if(confirm("确实要删除吗?")){ 把ajax方法放到这礼拜 }else{ //alert("已经取消了删除操作"); } } 示例: <?php if(in_array(23,$user_vips)){ ?> <a href="javascript:del(<?=$info['id']; ?>);"><?php echo L('delete')?></a> <?php } ?> js文件代码: <script> function del(id){ $.ajax({ type:'post', cache:false, dataType:'json', url:'index.php?m=admin&c=diy&a=delete&id='+id+'&pc_hash=<?=$_SESSION["pc_hash"]; ?>', error:function(e){alert(e.responseText);}, success:function(d) { if(d.state=='success') { toastr.success(d.msg); setTimeout(function(){location.href='index.php?m=admin&c=diy&a=init&pc_hash=<?php echo $_SESSION['pc_hash']; ?>';},1500); } else { toastr.error(d.msg); } } }) } </script> 上面的js删除没有弹出确认。下面要进行改造: <script> function del(id){ if(confirm("确实要删除吗?")){ $.ajax({ type:'post', cache:false, dataType:'json', url:'index.php?m=admin&c=diy&a=delete&id='+id+'&pc_hash=<?=$_SESSION["pc_hash"]; ?>', error:function(e){alert(e.responseText);}, success:function(d) { if(d.state=='success') { toastr.success(d.msg); setTimeout(function(){location.href='index.php?m=admin&c=diy&a=init&pc_hash=<?php echo $_SESSION['pc_hash']; ?>';},1500); } else { toastr.error(d.msg); } } }) }else{ //alert("已经取消了删除操作"); } } </script>
原创文章,作者:ItWorker,如若转载,请注明出处:https://blog.ytso.com/tech/courses/262983.html