我有我的脚本视图猫的代码
<table align="center" width="100%" cellpadding="0" cellspacing="0" border="0">
<td class="td1" width="70%" align="center">title</td>
<td class="td2" width="30%" align="center">Delete</td>
</tr>
<?php
$select_cats = $mysqli->query("SELECT * FROM cats");
$num_cats = $select_cats->num_rows;
while ($rows_cats = $select_cats->fetch_array(MYSQL_ASSOC)){
$id_cat = $rows_cats ['id'];
$title_cat = $rows_cats ['title'];
?>
<tr rel="<? echo $id_cat; ?>">
<td class="td1" width="70%" align="center"><a class="link2" href="../cat-<? echo $id_cat; ?>.html" target="_blank"><? echo $title_cat ; ?></a></td>
<td class="td2" width="30%" align="center">
<a rel="<? echo $id_cat; ?>" class="deletecat" href="#">Delete Cat</a>
<span class="loading" rel="<? echo $id_cat; ?>"></span>
</td>
</tr>
<?
}
?>
我使用这个jquery代码删除cat
<script type="text/javascript">
$(document).ready(function(){
$(".deletecat") .click(function(){
var id_cat = $(this).attr('rel');
var s = {
"id_cat":id_cat
}
$.ajax({
url:'action/delete_cat.php',
type:'POST',
data:s,
beforeSend: function (){
$(".loading[rel="+id_cat+"]") .html("<img src=\"../style/img/load.gif\" alt=\"Loading ....\" />");
},
success:function(data){
$("tr[rel="+id_cat+"]") .fadeOut();
}
});
return false;
});
});
</script>
我希望alert();
在对话框中生成验证消息有两个选项
如果单击是执行jquery代码,如果单击无关闭对话框
谢谢
答案 0 :(得分:4)
您可以使用confirm()对话框要求用户确认操作,如果没有确认退出而没有像
这样的jQuery操作$(document).ready(function () {
$(".deletecat").click(function () {
//show the confirmation
if(!confirm('do you want to proceed')){
return
}
var id_cat = $(this).attr('rel');
var s = {
"id_cat": id_cat
}
$.ajax({
url: 'action/delete_cat.php',
type: 'POST',
data: s,
beforeSend: function () {
$(".loading[rel=" + id_cat + "]").html("<img src=\"../style/img/load.gif\" alt=\"Loading ....\" />");
},
success: function (data) {
$("tr[rel=" + id_cat + "]").fadeOut();
}
});
return false;
});
});
答案 1 :(得分:0)
您可以在ajax连接之前添加此代码,
if (!confirm("Are You Sure?")) {
return false;
}
答案 2 :(得分:0)
这样做
$(document).ready(function(){
$(".deletecat") .click(function(){
confirm here
if(!confirm("Are you sure you want to delete?")){
return; // i.e return if user selects no. otherwise proceed.
}
var id_cat = $(this).attr('rel');
var s = {
"id_cat":id_cat
}
$.ajax({
url:'action/delete_cat.php',
type:'POST',
data:s,
beforeSend: function (){
$(".loading[rel="+id_cat+"]") .html("<img src=\"../style/img/load.gif\" alt=\"Loading ....\" />");
},
success:function(data){
$("tr[rel="+id_cat+"]") .fadeOut();
}
});
return false;
});
});