我有一個表,看起來像這樣的標題行:刪除畢竟其他行已被刪除
<table>
<tr id="header">
<th>Title</th>
<th>Title</th>
</tr>
<tr id="1" class="record">
<td><a class="delbutton">X</a></td>
<td>Some Data</td>
</tr>
<tr id="2" class="record">
<td><a class="delbutton">X</a></td>
<td>Some Data</td>
</tr>
</table>
而且我有一個jQuery腳本:
$(function() {
$(".delbutton").click(function(){
//Save the link in a variable called element
var element = $(this);
//Find the id of the link that was clicked
var del_id = element.attr("id");
//Built a url to send
var info = 'del_id=' + del_id;
if(confirm("Are you sure you want to delete this entry? This cannot be undone.")) {
$.ajax({
type: "GET",
url: "delete_entry.php",
data: info,
success: function(){
}
});
$(this).parents(".record").animate({ backgroundColor: "#fbc7c7" }, "fast")
.animate({ opacity: "hide" }, "slow");
}
return false;
});
});
我是什麼試圖做的是刪除標題行(id =「header」),或者更好的是,刪除最後一個數據行之後的其餘表。
任何指導意見將是巨大的
更新: 以下湯姆的建議後,我試圖計算的行。 我試着用:
$('.record').size()
但始終報告行的初始數量 - 它從來沒有準確地報告行數我刪除行之後。是否有可能以某種方式跟蹤剩餘的行?
分辨率 這工作:
$(function() {
$(".delbutton").click(function(){
//Save the link in a variable called element
var element = $(this);
//Find the id of the link that was clicked
var del_id = element.attr("id");
//Built a url to send
var info = 'del_id=' + del_id;
if(confirm("Are you sure you want to delete this entry? This cannot be undone.")) {
$.ajax({
type: "GET",
url: "delete_entry.php",
data: info,
success: function(){
}
});
$(this).parents(".record").animate({ backgroundColor: "#fbc7c7" }, "fast")
.animate({ opacity: "hide" }, "slow");
//Remove - don't just hide
$(this).parents(".record").remove();
//If there are no more deleteable rows, delete the header
if($('.record').length == 0) {
$('#existTitle').animate({ backgroundColor: "#fbc7c7" }, "fast").animate({ opacity: "hide" }, "slow");
}
}
return false;
});
});
試$( '記錄')的長度,而不是 - 確保你做這裏面的功能,因此被更新。 – 2010-01-21 21:50:48
只爲嘗試我添加警報($('。record')。length);在if(configm ...在函數之前,它並沒有得到更新:-( – Jason 2010-01-21 21:59:17
我在想計數不會改變,因爲我只隱藏元素... – Jason 2010-01-21 22:02:24