大家好我在我的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">×</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);
}
如果我直接删除数据但是如果我使用模态不工作,这个控制器代码是有效的..我希望有人可以帮助我..
答案 0 :(得分: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>
答案 1 :(得分:0)
删除此行,它将起作用
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
});