gpt4 book ai didi

javascript - jquery如何获取 parent 的姓名

转载 作者:数据小太阳 更新时间:2023-10-29 04:04:47 24 4
gpt4 key购买 nike

我正在搜索提供父级名称的元素。这:

            $('.Item').click(function(){
var a = $(this).parent();
alert(a[0].tagName);
});

只是说“DIV”,但我需要一个元素的真实名称。谢谢

最佳答案

尝试以下(提醒标签名称,然后是真实姓名):

我使用了 $(a[0]).attr('name');

例如

$('.Item').click(function() {
var a = $(this).parent();
alert(a[0].nodeName.toLowerCase()); //Tag Name

alert($(a[0]).attr('name')); //Attribute (real) name
//OR
alert(a.attr('name')); //Attribute (real) name
});

关于javascript - jquery如何获取 parent 的姓名,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6840291/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com