Jquery 单击同一单元格中的链接时获取隐藏字段值

Jquery 单击同一单元格中的链接时获取隐藏字段值,jquery,Jquery,我正在使用asp.net数据列表,当单击该单元格的定位点时,我必须找到隐藏的字段值 我尝试使用parent(),closest() $('.document').ready(函数(){ $('.addtocompare').bind('click',函数(){ var hdnProductId=$(this.parent().find('.hdnProductId input[type=hidden]')).val(); 警报(hdnProductId); 返回false; }); });

我正在使用asp.net数据列表,当单击该单元格的定位点时,我必须找到隐藏的字段值

我尝试使用
parent()
closest()


$('.document').ready(函数(){
$('.addtocompare').bind('click',函数(){
var hdnProductId=$(this.parent().find('.hdnProductId input[type=hidden]')).val();
警报(hdnProductId);
返回false;
});
});

使用
.parents()

使用
.parents()

像这样吗

$(this).children('input[type=hidden]').val();
像这样

$(this).children('input[type=hidden]').val();
parent()为您提供了一个级别的父项…因为您的隐藏inout在
使用父项(.tdClass)中,而您在查找中编写的代码不正确

试试这个

var hdnProductId = $(this).parents(".tdClass").find('.hdnProductId  input[type=hidden]').val();
parent()为您提供了一个级别的父项…因为您的隐藏inout位于
使用父项(“.tdClass”)中,而您在其中编写的代码查找不正确

试试这个

var hdnProductId = $(this).parents(".tdClass").find('.hdnProductId  input[type=hidden]').val();

您好,我更新了您的JSFIDLE,请检查

请注意

var hdnProductId = $(this).parents().find(".hdnProductId  input[type=hidden]").val();

您好,我更新了您的JSFIDLE,请检查

请注意

var hdnProductId = $(this).parents().find(".hdnProductId  input[type=hidden]").val();
您可以这样做:

var hdnProductId = $(this).parents('.CollectionLeftbottom').siblings(".CollectionLeftTop").find('.hdnProductId  input[type=hidden]').val();
演示:

您可以这样做:

var hdnProductId = $(this).parents('.CollectionLeftbottom').siblings(".CollectionLeftTop").find('.hdnProductId  input[type=hidden]').val();
演示:

您可以这样做:

var hdnProductId = $(this).closest('td')
                          .find('.hdnProductId  input[type=hidden]').val();
只需找到所单击项目的
.closest()
td,并在
中找到
输入[type=hidden]

请注意:

这是无效的:

$('.document')
更改为:

$(document)
您可以这样做:

var hdnProductId = $(this).closest('td')
                          .find('.hdnProductId  input[type=hidden]').val();
只需找到所单击项目的
.closest()
td,并在
中找到
输入[type=hidden]

请注意:

这是无效的:

$('.document')
更改为:

$(document)

$('.document')
应该是
$(document)
$('.document')
应该是
$(document)
您使用了var hdnProductId=$(this).parents().find('.hdnProductId输入[type=hidden]:first').val();在jsfidlle中,但在aswer中,我认为您错过了第一个。我是rt吗?哦,那只是一个测试,
:首先不需要
父级()和父级()之间的差异?
parent()
只上升一级,
parents()
上升多级,使用
parents()
不带选择器将尝试在每个父级中查找。因此,请使用类似于我的回答中的选择器。您使用了var hdnProductId=$(this).parents().find('.hdnProductId input[type=hidden]:first').val();在jsfidlle中,但在aswer中,我认为您错过了第一个。我是rt吗?哦,那只是一个测试,
:首先不需要
父级()和父级()之间的差异?
parent()
只上升一级,
parents()
上升多级,使用
parents()
不带选择器将尝试在每个父级中查找。所以请使用我的答案中的选择器