按类名和值-jquery过滤元素 [英] Filter elements by class name and value-jquery
本文介绍了按类名和值-jquery过滤元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在我的表单中,我有很多名为myClass的元素。我正在使用.each函数迭代这些元素。
i想要找到具有此类名称的最后元素的索引,具有值(值不为空)...我该怎么办?
In my form i have many elements with class named "myClass" . i am iterating these elements using .each function. i want to find the index of the last elements which has this class name and has value(value not empty) ... how can i do it?
$(":text[name^=distanceSlab]").each(function(i){
var Indx = // find the index of the last element which has class name= myClass and has value
});
提前致谢
推荐答案
$(":text[name^=distanceSlab]").each(function(i, value) {
alert(i + ': ' + value);
});
上面显示了如何获取每个元素的索引......但我不确定选择器是什么你需要提出问题。您可以像这样使用类名作为选择器:
The above shows you how to get index for each element ... but I am not sure what selector you require from your question. You can just use class name as selector like this :
$(".myClass").each(function(i, value) {
alert(i + ': ' + value);
});
要查找最后一个元素,请使用。last(),如下所示:
To find the last element use .last(), like so :
$('.myClass').last();
将选择器组合起来找到最后一个值:
Combine selectors to find last with a value :
$('.myClass[value!=""]').last();
这篇关于按类名和值-jquery过滤元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文