我是jQuery的noob ...我希望我已经解释得很清楚了;我有一个<ul>
标题,当我使用$.post
将一个条目添加到动态创建的列表时出现。添加的每个条目都有一个与其关联的删除/编辑按钮。当所有条目被删除时,jQuery隐藏ul标题
标题是这样的:
<ul class="addedItems">
<li>Month</li>
<li>Year</li>
<li>Cottage</li>
<li><span class="edit">edit</span></li>
<li><span class="del">delete</span></li>
</ul>
This all looks like this:
Month Year Cottage <--this appears after I've added an entry
-------------------------------- and I want it to stick around unless
all items are deleted.
Dec 1990 Fir edit/delete <--entries
Jan 2000 Willow edit/delete
我的问题是:是否有某种条件,我可以用jQuery使用隐藏class="header"
如果创建的
<ul class="header">
<li>Month</li>
<li>Year</li>
<li>Cottage</li>
</ul>
我的动态列表所有的项目都被删除?我已经阅读了条件语句,如is
和not
与jq,但我并不真正了解他们的工作方式。 class="addedItems"
中的所有项目都存储在由JSON生成的data
中。
这是删除功能:
$(".del").live("click", function(){
var del = this;
var thisVal = $(del).val();
$.post("delete.php", { dirID : thisVal },
function(data){
if(confirm("Are you sure you want to DELETE this entry?") == true) {
if(data.success) {
//hide the class="header" here somwhere??
$(del).parents(".addedItems").hide();
} else if(data.error) {
// throw error if item does not delete
}
}
}, "json");
return false;
}); //end of .del function
这里是delete.php
<?php
if($_POST) {
$data['delID'] = $_POST['dirID'];
$query = "DELETE from //tablename WHERE dirID = '{$data['delID']}' LIMIT 1";
$result = $db->query($query);
if($result) {
$data['success'] = true;
$data['message'] = "Entry was successfully removed.";
} else {
$data['error'] = true;
$data['message'] = "Item could not be deleted.";
}
echo json_encode($data);
}
?>
@Ghommey无法让它工作...... grr。 – Scott 2009-10-06 09:25:09
男人...仍然没有运气。你可以在“live”点击功能中加入“each”吗?应该不重要吗? – Scott 2009-10-06 09:37:18
试试这个。你得到一个JavaScript错误? – jantimon 2009-10-06 10:02:13