【问题标题】:Use modal bootstrap as delete prompt in Codeigniter在 Codeigniter 中使用模态引导作为删除提示
【发布时间】:2017-12-20 00:54:36
【问题描述】:

大家好,我在 CI 脚本上使用 Modal 作为删除提示,但它无法正常工作,可能有错误。任何人都可以为我检查代码。

删除按钮上的代码:

<a onclick="confirm_modal(<?php echo base_url('threads/deletereplytopic/'.$toprep['id']) ?>)" style="cursor:pointer;" data-toggle="modal"  data-target="#deleteReplyTopic"><i class="fa fa-trash-o" aria-hidden="true"></i></a>

还有我在 Modal 和 Js 中的代码:

<!-- Delete Topic Reply  Modal-->
<div class="modal fade" id="deleteReplyTopic" style="display: none;" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <h6 class="modal-title"><?php echo lang_key('confirm_delete'); ?></h6>
                <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                    <span aria-hidden="true">&times;</span>
                </button>
            </div>
            <div class="modal-body">
                <?php echo lang_key('confirm_delete_text'); ?>
            </div>
            <div class="modal-footer">
                <a class="btn btn-danger" id="delete_topic_reply" href=""><?php echo lang_key('delete'); ?></a>
                <button type="button" class="btn btn-info" data-dismiss="modal" id="delete_cancel_link"><?php echo lang_key('cancel'); ?></button>       
            </div>
        </div>
    </div>
</div>

还有 Js:

<!-- Delete Topic JS -->
<script>    
    function confirm_modal(delete_url)
    {
        jQuery('#deleteReplyTopic').modal('show', {backdrop: 'static',keyboard :false});
        jQuery("#deleteReplyTopic .grt").text(title);
        document.getElementById('delete_topic_reply').setAttribute("href" , delete_url );
        document.getElementById('delete_topic_reply').focus();
    }
</script>

这是我的控制器代码:

public function deletereplytopic($id='') {

        $deletereply = array(
                'id' => $id,
                'status' => 0
                );
        $deltop = 'confirmdelete';
        $this->session->set_flashdata('deltop', $deltop);   
        $this->topic_model->deleteReplyTopic($deletereply);
    }

如果我直接删除数据,这个控制器代码可以工作,但如果我使用模态不工作..希望有人能帮助我..

【问题讨论】:

  • 您是否在控制台中收到错误消息?如果您监视网络流量,那么带有 deletereplytopic 的控制器是否被调用/服务于内部服务器错误?我也没有看到您发送数据或访问控制器,只是设置属性。
  • 别在意最后一句话。
  • 我认为您缺少引号,例如confirm_modal('something')
  • 我稍后会尝试重新编码
  • 它现在可以工作了,我只是在点击按钮中的 之前和之后错过了这段代码“'”。 .

标签: javascript php jquery twitter-bootstrap codeigniter


【解决方案1】:

您在例如内部缺少引号confirm_modal('something')

<a onclick="confirm_modal('<?php echo base_url('threads/deletereplytopic/'.$toprep['id']) ?>')" style="cursor:pointer;" data-toggle="modal"  data-target="#deleteReplyTopic"><i class="fa fa-trash-o" aria-hidden="true"></i></a>

【讨论】:

  • 是的,这就是我现在所做的工作,呵呵,谢谢亚历克斯
【解决方案2】:

去掉这行就可以了

jQuery("#deleteReplyTopic .grt").text(title);

它不起作用,因为标题没有传递给函数

编辑: 使用以下代码更清晰

    <a  data-delurl="<?php echo base_url('threads/deletereplytopic/'.$toprep['id']) ?>" style="cursor:pointer;" data-toggle="modal"  data-target="#deleteReplyTopic"><i class="fa fa-trash-o open-dialog" aria-hidden="true"></i></a> 


        $(document).on("click", ".open-dialog", function () {

           $("a").attr("href", $(this).data('delurl'));


        });  

你也可以使用下面的,但不传递参数

         $('#deleteReplyTopic').on('shown.bs.modal', function () {
             //do stuff when modal opens

         });         

【讨论】:

  • 真的吗?!我使用 firefox 进行了测试,直到注释掉该行才有效。你最好在 Firefox 中测试你的代码
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2017-02-19
  • 2015-05-22
  • 1970-01-01
  • 1970-01-01
  • 2013-12-17
  • 1970-01-01
  • 2016-05-07
相关资源
最近更新 更多