我创建了一个删除按钮,使用jquery和ajax从我的数据库中删除一行。当我点击按钮时出现错误:Uncaught ReferenceError: element is not defined.
然后高亮显示var del_id = element.attr("id");
<a href="#" id="14" class="delbutton"><i class ="fa fa-trash"></i></a>
<script type="text/javascript">
$(function() {
$(".delbutton").click(function(){
var del_id = element.attr("id");
var info = 'id=' + del_id;
if(confirm("Sure you want to delete this?"))
{
$.ajax({
type: "POST",
url: "feed/deletepost",
data: info,
success: function(){
}
});
$(this).parents(".record").animate({ backgroundColor: "#fbc7c7" }, "fast")
.animate({ opacity: "hide" }, "slow");
}
return false;
});
});
</script>
关于可能导致这种情况的任何想法?
答案 0 :(得分:3)
这是因为element
未定义:D尝试这样做:
$(".delbutton").click(function(){
var del_id = $(this).attr("id");....
问候