php – Javascript确认删除

前端之家收集整理的这篇文章主要介绍了php – Javascript确认删除前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我正在创建一个简单的cms,我有以下内容
<input type="submit" value="delete" title="Delete Aricle(s)" id="delete_btn" onclick="delete_confirm()" />

<tbody>
  <?PHP foreach ($articles as $article): ?>
  <tr>
    <td align="center">
    <input id="article_id"name="article[]" type="checkBox" value="<?PHP echo $article->id; ?>" /></td>
    <td align="center"><?PHP echo anchor('admin/articles/edit/'.$article->id,$article->title); ?></td>
    <td align="center"><?PHP echo $article->author; ?></td>
    <td align="center"><?PHP echo $article->category; ?></td>
    <td align="center"><?PHP published($article->post_status); ?></td>
    <td align="center"><?PHP featured($article->featured); ?></td>
    <td align="center"><?PHP echo $article->views; ?></td>
    <td align="center"><?PHP echo $article->post_date; ?></td>
  </tr>
  <?PHP endforeach;?>
  </tbody>

上面的代码包含在表单标记

这是我的javascript代码

function delete_confirm() {
    var msg = confirm('Are you sure you want to delete the selected article(s)');
    if(msg == false) {
        return false;
    }
}

这是我的控制器中的删除功能

function articles_delete() {
        //Load Model
        $this->load->model("article_model");
        //Assign article id to variable
        $checkBox = $_POST['article'];
        //loop through selected checkBox
        for($i = 0; $i < count($checkBox); $i++) {
            //Call delete method of the article model
            $this->article_model->delete($checkBox[$i]);
        }
        $this->session->set_flashdata("message","Article(s) Deleted");
        redirect("admin/articles","refresh");
     }

但是,如果在确认对话框中单击了取消,则表单仍然会被提交并删除所选文章.
请告知如何做

尝试改变

< input type =“submit”value =“delete”title =“删除Aricle(s)”id =“delete_btn”onclick =“delete_confirm()”/>

< input type =“submit”value =“delete”title =“删除Aricle(s)”id =“delete_btn”onclick =“return delete_confirm();” /> 您正在onclick函数中运行delete_confirm()函数.你需要从onclick()函数本身返回false.

原文链接:https://www.f2er.com/php/130986.html

猜你在找的PHP相关文章