我有一些像这样的代码:
<?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 } ?>
我有两个名为Edit
和Delete
的链接。我想当用户点击Delete
链接时,会出现一个带有javascript的确认窗口,如果用户点击该确认窗口上的ok
,则执行deleteVip
方法。
我怎么能有这样的东西?
(我正在使用codeigniter
框架)
由于
答案 0 :(得分: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>
答案 1 :(得分: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>
答案 2 :(得分: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();" />
答案 3 :(得分: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>
&#13;