首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何在codeigniter中使用jquery-confirm?

如何在codeigniter中使用jquery-confirm?
EN

Stack Overflow用户
提问于 2018-02-19 12:03:15
回答 3查看 167关注 0票数 1

我一直在尝试使用https://craftpip.github.io/jquery-confirm/#ajaxloading提供的jquery-confirm。没有错误,但是当我尝试删除一个条目时,jquery会弹出一个警告,但是当我单击“is”时,它没有删除条目。谢谢你的帮助

这是php代码:

代码语言:javascript
复制
<div class="box">
    <div class="box-body">
        <a href="<?php echo base_url(); ?>admin/inputrequest" class="btn bg-green btn-flat">Input Request</a>
        <br><br>
        <table id="tabelrequest" class="table table-bordered table-striped">
            <thead>
                <tr>
                    <th>No.</th>
                    <th>Item Code</th>
                    <th>Description</th>
                    <th>Qty</th>
                    <th>Delete</th>
                    <th>Edit</th>
                    <th>Photo</th>
                </tr>
            </thead>
            <tbody>
                <?php
                    $no = 1;
                    foreach($allrequest as $request)
                    {
                        $delete_url = base_url().'admin/deleterequest/'.$request->id_request;
                        $update_url = base_url().'admin/updaterequest/'.$request->id_request;
                        $add_url = base_url().'admin/datafotorequest/'.$request->id_request;
                ?>
                        <tr>
                            <td><?php echo $no; ?></td>
                            <td><?php echo $request->item_code; ?></td>
                            <td><?php echo $request->description; ?></td>
                            <td><?php echo $request->qty; ?></td>
                            <td class="col-xs-1" style="text-align: center;"><a class="btn bg-olive btn-flat" class="delete" data-title="Are you sure you want to delete this item?" name="delete" href="<?php echo $delete_url; ?>"><i class="glyphicon glyphicon-trash"></i></a></td>
                            <td class="col-xs-1" style="text-align: center;"><a class="btn bg-teal btn-flat" name="update" href="<?php echo $update_url; ?>"><i class="glyphicon glyphicon-pencil"></i></a></td>
                            <td class="col-xs-1" style="text-align: center;"><a class="btn bg-red btn-flat" name="add" href="<?php echo $add_url; ?>"><i class="glyphicon glyphicon-camera"></i></a></td>
                        </tr>
                <?php
                        $no++;
                    }            
                ?>
            </tbody>
        </table>    
    </div>
</div>

这是我从jquery-confirms.js获取的jquery

代码语言:javascript
复制
<script>

    $('#delete').confirm({
        content: "",
    });
    $('#delete').confirm({
        buttons: {
            hey: function(){
                location.href = this.$target.attr('href');
            }
        }
    });

</script>
EN

回答 3

Stack Overflow用户

回答已采纳

发布于 2018-02-19 13:09:36

而不是这个

代码语言:javascript
复制
<td class="col-xs-1" style="text-align: center;">
    <a class="btn bg-olive btn-flat" class="delete" data-title="Are you sure you want to delete this item?" name="delete" href="<?php echo $delete_url; ?>">
        <i class="glyphicon glyphicon-trash"></i>
    </a>
</td>

我将使用(onclick="return confirm()")

代码语言:javascript
复制
<td class="col-xs-1" style="text-align: center;">
    <a class="btn bg-olive btn-flat" class="delete" onclick="return confirm('Are you sure you want to delete this item?');"  href="<?php echo $delete_url; ?>">
        <i class="glyphicon glyphicon-trash"></i>
    </a>
</td>
票数 1
EN

Stack Overflow用户

发布于 2018-02-19 12:15:54

我认为你必须像这样使用

代码语言:javascript
复制
<div class="box">
    <div class="box-body">
        <a href="<?php echo base_url(); ?>admin/inputrequest" class="btn bg-green btn-flat">Input Request</a>
        <br><br>
        <table id="tabelrequest" class="table table-bordered table-striped">
            <thead>
                <tr>
                    <th>No.</th>
                    <th>Item Code</th>
                    <th>Description</th>
                    <th>Qty</th>
                    <th>Delete</th>
                    <th>Edit</th>
                    <th>Photo</th>
                </tr>
            </thead>
            <tbody>
                <?php
                    $no = 1;
                    foreach($allrequest as $request)
                    {
                        $delete_url = base_url().'admin/deleterequest/'.$request->id_request;
                        $update_url = base_url().'admin/updaterequest/'.$request->id_request;
                        $add_url = base_url().'admin/datafotorequest/'.$request->id_request;
                ?>
                        <tr>
                            <td><?php echo $no; ?></td>
                            <td><?php echo $request->item_code; ?></td>
                            <td><?php echo $request->description; ?></td>
                            <td><?php echo $request->qty; ?></td>
                            <td class="col-xs-1" style="text-align: center;"><a class="btn bg-olive btn-flat delete"  data-title="Are you sure you want to delete this item?" name="delete" href="<?php echo $delete_url; ?>"><i class="glyphicon glyphicon-trash"></i></a></td>
                            <td class="col-xs-1" style="text-align: center;"><a class="btn bg-teal btn-flat" name="update" href="<?php echo $update_url; ?>"><i class="glyphicon glyphicon-pencil"></i></a></td>
                            <td class="col-xs-1" style="text-align: center;"><a class="btn bg-red btn-flat" name="add" href="<?php echo $add_url; ?>"><i class="glyphicon glyphicon-camera"></i></a></td>
                        </tr>
                <?php
                        $no++;
                    }            
                ?>
            </tbody>
        </table>    
    </div>
</div>

<script>

    $('.delete').confirm({
        content: "",
    });
    $('.delete').confirm({
        buttons: {
            hey: function(){
                location.href = this.$target.attr('href');
            }
        }
    });

</script>
票数 1
EN

Stack Overflow用户

发布于 2018-02-19 12:23:43

您需要创建ajax请求

HTML

代码语言:javascript
复制
<td class="col-xs-1" style="text-align: center;"><a class="btn bg-olive btn-flat" class="delete" data-title="Are you sure you want to delete this item?" name="delete" href="#" onclick="deleteRecord('<?php echo $request->id_request;?>');"><i class="glyphicon glyphicon-trash"></i></a></td>

AJAX

代码语言:javascript
复制
function deleteRecord(id)
{

            jQuery.ajax({
                type: "GET",
                url: '/admin/deleterequest/'+id,
                async: false,
                success: function (data)
                {
                    alert('success');
                }
            });

}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/48859381

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档