车荣汽车网
您的当前位置:首页jQuery实现查找最近父节点的方法

jQuery实现查找最近父节点的方法

来源:车荣汽车网


本文实例讲述了jQuery实现查找最近父节点的方法,对于jQuery不太熟的同学们,我们一起来学习jQuery吧!

这里演示查找当前控件最近的table代码:

<html>
 <head>
 <title>usually function</title>
 </head>
 <body>
 <table name="name_table1">
 <tr>
 <td>table1</td>
 </tr>
 </table>
 <table name="name_table2">
 <tr>
 <td>table2</td>
 </tr>
 </table>
 <table name="name_table3">
 <tr>
 <td>table3</td>
 </tr>
 </table>
 </body>
<html>
<script type="text/javascript" src="jquery-1.4.4.js"></script>
<script>
$(function(){
 $("td").bind("click",function(){
 //alert($(this).html());
 alert($(this).closest("table").attr("name"));
 });
});
</script>
显示全文