使用jquery从循环div获取隐藏值

使用jquery从循环div获取隐藏值,jquery,loops,Jquery,Loops,我有一个搜索按钮。单击搜索按钮时,将生成以下代码: <div class = 'clickedResult' title = 'click to see details'> <table>the result will br written in this table </table> <input type = 'hidden' class = 'form_id' value = '$form_id' /> <input type

我有一个搜索按钮。单击搜索按钮时,将生成以下代码:

<div class = 'clickedResult' title = 'click to see details'>
 <table>the result will br written in this table </table>
 <input type = 'hidden' class = 'form_id' value = '$form_id' /> 
 <input type = 'hidden' class = 'status' value = '$status' />
 </div> <br/>
它将向14和48发出警报。。。如果单击第一个表,如何仅向14发出警报?如果我单击第二个表,它将发出警报48?

使用
$(this).children(“input.form\u id”)
而不是
$('.clickedResult input.form\u id')
只检查作为所单击div的后代的表单id

$(".clickedResult").click(function() {
  alert($(this).find('input.form_id').val());
});
考虑到您的示例,代码如下所示:

$(".clickedResult").click(function() {
    console.log( $(this).children("input.form_id").val() );
});

还有人可能会说,在您的情况下,使用
.children()
而不是
.find()
更快,因为您的输入只比div低一个dom级别,并且
.children()
只搜索一个级别的深度,而
.find()
遍历整棵树以查找所有可能的候选对象。

使用单击处理程序中的
事件
参数,如下所示:

$(".clickedResult").click(function() {
  alert($(this).find('input.form_id').val());
});
$(".clickedResult").click(function() {
    console.log( $(this).children("input.form_id").val() );
});