2013-08-18 69 views
-4

如何创建一个删除确认对话框?如果'是'点击删除该消息,如果'否'点击取消删除操作。引导确认对话框中PHP

Popup dialog

目前我有这样的,我认为:

<a href="javascript:;" class="btn btn-large btn-info msgbox-confirm">Confirm Message</a> 

而如何改变对话框的内容?

+2

我真的不明白你的意思。你在问如何用JS/Jquery来开发流程或接受/拒绝,还是用PHP来使用页面重新加载,或者一般情况下?“改变对话框内容”是什么意思?点击后按钮消失? – Rober

+0

Robert,Am只是问,如果被点击意味着我需要在控制器中调用一种方法,如果没有或取消点击意味着它不应该做任何事情。 –

+0

此代码用于PHP中的Confirmation Dialog解决了我的问题。 '

' 'Delete' –

回答

2

您不能在PHP中进行确认或引导确认,因为PHP是服务器端代码。

你将要做的是如何使用Javascript创建一个确认框。

普通的JavaScript

使用普通标准的JavaScript这将只需要一个按钮的功能

HTML

<button onclick="show_confirm()">Click me</button> 

的JavaScript

// function : show_confirm() 
function show_confirm(){ 
    // build the confirm box 
    var c=confirm("Are you sure you wish to delete?"); 

    // if true 
    if (c){ 
     alert("true"); 
    }else{ // if false 
     alert("false"); 
    } 
    } 

Demo jsFiddle

引导与jQuery

这种方式是一个小如您在第三方库,增加更多的复杂。

要开始与您一起将需要创建一个模式作为您的确认框。

HTML

<div id="confirmModal" class="modal hide fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true"> 
    <div class="modal-header"> 
    <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button> 
    <h3 id="myModalLabel">Delete?</h3> 
    </div> 
    <div class="modal-body"> 
    <p>Are you sure you wish to delete?</p> 
    </div> 
    <div class="modal-footer"> 
    <button class="btn" data-dismiss="modal" aria-hidden="true">Cancel</button> 
    <button onclick="ok_hit()" class="btn btn-primary">OK</button> 
    </div> 
</div> 

相同的按钮与以前的造型

<button class="btn btn-danger" onclick="show_confirm()">Click me</button> 

然后

的Javascript

// function : show_confirm() 
function show_confirm(){ 
    // shows the modal on button press 
    $('#confirmModal').modal('show'); 
} 

// function : ok_hit() 
function ok_hit(){ 
    // hides the modal 
    $('#confirmModal').modal('hide'); 
    alert("OK Pressed"); 

    // all of the functions to do with the ok button being pressed would go in here 
} 
一点点

Demo jsFiddle

1

与JavaScript一个简单的方法:

<a onclick="if(!confirm('Are you sure that you want to permanently delete the selected element?'))return false" class="btn btn-large btn-info msgbox-confirm" href="?action=delete">Delete</a> 

这样,当“删除”用户点击,出现一个对话框询问她/他确认。如果它被接受,页面将被重新加载一个url中的参数(改为任何你需要的)。否则,对话框关闭并且什么都不会发生。

+0

罗伯,我需要确认对话框样式作为上面的图像,但上述答案解决了一半的问题 –

0
<script> 
function deletechecked() 
{ 
    var answer = confirm("Are you sure that you want to permenantly delete the selected element?") 
    if (answer){ 
     document.messages.submit(); 
    } 

    return false; 
} 
</script> 

<a href="<?php echo base_url('department/deletedept/'.$row['dept_id']);?>" onclick="return deletechecked();" title="Delete" data-rel="tooltip" class="btn btn-danger">