Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/73.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript jQuery获取a<;中两个文本字段的值;p>;或<;部门>;_Javascript_Jquery - Fatal编程技术网

Javascript jQuery获取a<;中两个文本字段的值;p>;或<;部门>;

Javascript jQuery获取a<;中两个文本字段的值;p>;或<;部门>;,javascript,jquery,Javascript,Jquery,我需要获取中两个文本字段的值,以便通过ajax提交它们。我一直在思考如何有效地获取这些值。页面上有几个像这样的,我只需要获取容器的值,然后单击'Approve'或'Delete'。 我的方法很粗糙。你能推荐一些更优雅、更高效的吗 <body> <p class="rawData"> <span> <input class="minWeight" type="text" placeholder="Minimum Weight"> <input

我需要获取

中两个文本字段的值,以便通过ajax提交它们。我一直在思考如何有效地获取这些值。页面上有几个像这样的

,我只需要获取

容器的值,然后单击
'Approve'
'Delete'
。 我的方法很粗糙。你能推荐一些更优雅、更高效的吗

<body>

<p class="rawData">
<span>
<input class="minWeight" type="text" placeholder="Minimum Weight">
<input class="maxWeight" type="text" placeholder="Maximum Weight">
</span>
<span class="actions">
<i class="icon-accept blue approve"></i>
<i class="icon-reject blue delete"></i>
</span>
</p>

<p class="rawData">
<span>
<input class="minWeight" type="text" placeholder="Minimum Weight">
<input class="maxWeight" type="text" placeholder="Maximum Weight">
</span>
<span class="actions">
<i class="icon-accept blue approve"></i>
<i class="icon-reject blue delete"></i>
</span>
</p>

</body>

$('.approve,.delete').live('click', function() {

    var self = $(this);
    console.log(self.parent().parent()//find etc);

});

$('.approve,.delete').live('click',function(){ var self=$(这是); console.log(self.parent().parent()//查找等); });
我将使用
最近的
查找
原始数据的第一个父实例,然后从那里进行筛选:

$('.approve,.delete').on('click', function() {
    var $raw = $(this).closest(".rawData");
    console.log($raw.find("minWeight").val());
    console.log($raw.find("minWeight").val());
});

最近的(“p”)更有效here@jmenezes,请注意使用“on”而不是“live”。这是从1.7开始的。请记住这一点。他们没有唯一ID有什么原因吗?它们是在没有设定数量的情况下动态创建的吗?是的。它们是动态创建的。就像你在那里看到的那样。