这是有问题的代码:
$('a.delete').click(function(e) {
e.preventDefault();
var parent = $(this).parent();
$.ajax({
type: 'get',
url: 'deletemenu.php',
data: 'ajax=1&delete=' + parent.attr('id').replace('menu-',''),
beforeSend: function() {
parent.animate({'backgroundColor':'#fb6c6c'},300);
},
success: function() {
parent.slideUp(300,function() {
parent.remove();
});
$('.menusub').slideUp(300,function() {
$('.menusub').remove();
});
}
});
});
好的,我想做的是向上滑动并删除特定菜单下的所有子菜单(删除此菜单时)。现在我有$('.menusub').slideUp(300,function() {
$('.menusub').remove();
});
。为达到这个。当然,这段代码的问题在于它会使所有子菜单(具有 menusub 类)消失。我如何确保只有特定菜单下的子菜单才会消失?
顺便说一下,这是查看菜单的代码
$result = mysql_query("SELECT * FROM Menu") or die(mysql_error());
while($row = mysql_fetch_array($result)){
echo '<div class="menu" id="menu-',$row['menu_id'],'">';
echo $row['menu_name']. " - ". $row['menu_weight']. "<a class='delete' href='?delete=".$row['menu_id']."'> delete</a>";
echo '</div>';
$sub = mysql_query("SELECT * FROM SubMenu INNER JOIN Menu WHERE SubMenu.menu_id = Menu.menu_id AND Menu.Menu_id = ".$row['menu_id']."") or die(mysql_error());
while($subrow = mysql_fetch_array($sub)){
echo '<div class="menusub" id="menusub-',$subrow['submenu_id'],'">';
echo "-- ".$subrow['submenu_name']." - ".$subrow['submenu_weight']."<a class='deletesub' href='?deletesub=".$subrow['submenu_id']."'> delete</a><br/>";
echo '</div>';
}
}`
Tnx 回复!