Jquery获取当前元素父元素

<html>
<body>
<div id="p1">
    <div id="p2">
        <table>
            <tr>
                <td></td>
                <td>
                    <input type="text"/>
                    <input type="text"/>
                    <input type="text"/>
                </td>
                <td><button οnclick="f1(this)">按钮</button></td>
            </tr>


            <tr>
                <td></td>
                <td>
                    <input type="text"/>
                    <input type="text"/>
                    <input type="text"/>
                </td>
                <td><button οnclick="f1(this)">按钮</button></td>
            </tr>


            <tr>
                <td></td>
                <td>
                    <input type="text"/>
                    <input type="text"/>
                    <input type="text"/>
                </td>
                <td><button οnclick="f1(this)">按钮</button></td>
            </tr>

        </table>
    </div>
</div>
</body>
</html>

<script type="text/javascript">
     window.οnlοad=function(){
         
         function f1(obj){
                var tmp = obj;
                //触发点击事件时,获取当前点击元素的祖先元素tr中第二个td的第一个input输入的值
                //parents()获取所有的祖先元素td/tr/table/div/div/body/html
                //parents("tr")指定tr元素
                //children("td").eq(1)子节点中的第二个td
                //find("input:first").val()第一个input标签的值
                var value = $(obj).parents("tr").children("td").eq(1).find("input:first").val();
                alert(value);
            }
        
     }
</script> 

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值