Php 如何构建jQuery删除

Php 如何构建jQuery删除,php,javascript,jquery,Php,Javascript,Jquery,我有一些这样的 <script src="http://code.jquery.com/jquery-latest.js"></script> <table> <tr title="test" id="ex1"> <td><div class="move">Hello</div></td> <td>&nbsp;</td> <td>&a

我有一些这样的

<script src="http://code.jquery.com/jquery-latest.js"></script>
<table>
<tr title="test" id="ex1">
    <td><div class="move">Hello</div></td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
</tr>
<tr id="ex2">   
    <td><div class="move">Hello</div></td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
</tr>       
</table>

<button>Move</button>
<script>
$("button").click(function () {
    $(".move").remove();   
    });
</script>

非常感谢你

您可以简化此操作

$('.move').parents('tr').remove();
这将找到最近的父级,该父级也是
,并将其删除

……等等。那么您想单击一个按钮,然后让它仅删除具有该特定ID的一个div

那样的话,就用

$('.move').parents('#ex2').remove();
那就是

$("#ex2 .move").remove();
简单,是吗?请记住,jQuery选择器与CSS选择器相同。

请尝试以下方法:-

这样做的目的是在id为ex2的元素的所有子元素(上下文)中选择css类为move的元素,然后将其删除


选中此复选框以了解有关
jQuery(选择器,上下文)
语法的更多信息-

您可以使用更具体的选择器:


你好
你好
移动
移动2
$(“#按钮1”)。单击(函数(){
$(“#ex1.move”).remove();
});
$(“#按钮2”)。单击(函数(){
$(“#ex2.move”).remove();
});

如果ex2是一个类而不是一个id,我认为这实际上是最好的答案?它应该是$(“#ex2.move”).remove();它不应该是
$(“#ex2.move”).remove()
因为
ex2
是一个id?
$("#ex2 .move").remove();
$(".move", "#ex2").remove();
<table>
<tr title="test" id="ex1">
    <td><div class="move">Hello</div></td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
</tr>
<tr id="ex2">   
    <td><div class="move">Hello2</div></td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
</tr>       
</table>

<button id="button1">Move</button>
<button id="button2">Move 2</button>
<script>
$("#button1").click(function () {
    $("#ex1 .move").remove();   
});

$("#button2").click(function () {
    $("#ex2 .move").remove();   
});
</script>