2016-06-10 42 views
1

後,我有一些像這樣的代碼:運行PHP函數用戶確認

<?php foreach ($vips as $vip) { ?> 
    <tr> 
     <td><?php echo $vip['id'] ?></td> 
     <td><?php echo $vip['vip_name'] ?></td> 
     <td><a href="<?php echo base_url() ?>admin/editVip/<?php echo $vip['id'] ?>">Edit</a>/<a 
       href="<?php echo base_url() ?>admin/deleteVip/<?php echo $vip['id'] ?>">Delete</a></td> 
    </tr> 
<?php } ?> 

我有兩個環節叫EditDelete。我想當用戶點擊Delete鏈接一個確認窗口出現與JavaScript,如果用戶在該確認窗口上點擊ok,然後執行deleteVip方法。 我怎麼能有這樣的事情? (我使用codeigniter框架)

感謝

回答

2

添加錨標記本身確認;

<a href="<?php echo base_url(); ?>admin/deleteVip/<?php echo $vip['id']; ?>" onclick="return confirm('Are you sure you want to delete?')">Delete</a> 
0

function myFunction() { 
 
    var ss= confirm("are sure you want delete"); 
 
    
 
    if(ss==true) 
 
    { 
 
     alert("hi"); 
 
     return true; 
 
     
 
     
 
     } 
 
    else 
 
    
 
    { 
 
     alert("no"); 
 
     return fasle; 
 
     
 
     } 
 
}
<button onclick="myFunction()">Try it</button>

0

上按一下按鈕調用這個函數

function Confirm(){ 
var txt; 
var r = confirm("R u sure you want to delete this...!!!"); 
if (r == true) { 
    return true 
} else { 
    return false 
} 

,並在你的按鈕,你有權像下面

<input type="button" name="button" value="button" onclick="return Confirm();" /> 
0

下面是完整的代碼..

<!DOCTYPE html> 
 
<html> 
 
<body> 
 

 
<p>Click the button to display a confirm box.</p> 
 

 
<button onclick="myFunction()">Try it</button> 
 
<a href="javascript:void(0)" onClick="myFunction();">Delete</a> 
 
<p id="demo"></p> 
 

 
<script> 
 
function myFunction() { 
 
    var x; 
 
    if (confirm("Are you want to delete ?!") == true) { 
 
     x = "You pressed OK!"; 
 
    } else { 
 
     x = "You pressed Cancel!"; 
 
    } 
 
    document.getElementById("demo").innerHTML = x; 
 
} 
 
</script> 
 

 
</body> 
 
</html>