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有什么原因吗?它们是在没有设定数量的情况下动态创建的吗?是的。它们是动态创建的。就像你在那里看到的那样。