【发布时间】:2014-01-08 03:34:56
【问题描述】:
此代码有一个 ajax 脚本,用于删除记录并在删除时有动画。但是当我将 ajax 脚本与插件混合时,确认它不起作用。这个脚本有什么问题?
这是我的表格记录中的删除按钮。
<?php
echo' <tr class="record">
<td align="center"><a href="#" id="'.$row["counter"].'" class="delbutton"><img src="images/del.png"></a></td></tr>';
?>
带有确认插件的 Ajax
<script>
$(function() {
$(".delbutton").click(function(){
var element = $(this);
var del_id = element.attr("id");
var info = 'id=' + del_id;
$(function() {
$("<div />").attr("id", "dialog-confirm").append(
$("<p />").text('Are you sure?').css("text-align", "center").prepend(
$("<span />").addClass("ui-icon ui-icon-alert").css({
display: 'inline-block',
margin: '0px 7px 0px 0px'
})
)
).dialog({
resizable: false,
height:140,
modal: true,
buttons: {
"Delete all items": function() {
$.ajax({
type: "GET",
url: "delete.php",
data: info,
success: function(){
$(this).parents(".record").animate({ backgroundColor: "#fbc7c7" }, "fast").animate({ opacity: "hide" }, "slow");
}
});
$( this ).dialog( "close" );
},
Cancel: function() {
$( this ).dialog( "close" );
return false;
}
}
}); // end Dialog
return false;
}); // end .delbtn
});
}); // end jquery load
</script>
【问题讨论】:
-
这个
<script>标签和你的<script>标签的其余部分在哪里?如果在<head>标签中,那么您应该使用$(document).ready()。如果您的插件来自另一个非 jQuery 库,请使用$.noConflict()api.jquery.com/jQuery.noConflict 。
标签: javascript php jquery ajax