本文介绍了确认框在CodeIgniter锚链接中以删除记录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用以下代码从数据库中删除记录。但是我面临一个问题:当我在确认框中单击取消时,它将删除记录。如果单击取消,它将返回false,但如何删除记录?

I am using the following code to delete a record from a database. But I am facing a problem: when I click on "cancel" in the confirm box then it deletes the record. If I click cancel it returns false but how does it delete the record?

这是怎么回事?

Javascript代码:

Javascript code:

function ConfirmDialog() {
  var x=confirm("Are you sure to delete record?")
  if (x) {
    return true;
  } else {
    return false;
  }
}

视图中的PHP代码:

<?php
  echo anchor('user/deleteuser/'.$row->id, 'Delete', array('class'=>'delete', 'onclick'=>"return ConfirmDialog();"));
?>


推荐答案

尝试一下:

<a href="javascript:void(0);" onclick="delete(<?php echo $row->id;?>);">Delete</a>

并在脚本中使用它:

<script type="text/javascript">
    var url="<?php echo base_url();?>";
    function delete(id){
       var r=confirm("Do you want to delete this?")
        if (r==true)
          window.location = url+"user/deleteuser/"+id;
        else
          return false;
        } 
</script>

这篇关于确认框在CodeIgniter锚链接中以删除记录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-16 20:57