[英]Jquery each return only first found element
var x = $(".tabularData tr").each(function(){
if($(this).hasClass("even")||$(this).hasClass("odd")){
RETURN ONLY FIRST FOUND ELEMENT, WEATHER EVEN OR ODD
CURRENT CODE IS RETURNING ALL ELEMENTS
//return $(this);
}
});
return $(this)
is return all elements with even|odd whereas i need only return first found element. return $(this)
返回所有带有偶数| odd的元素,而我只需要返回第一个找到的元素。
If I 'm not misunderstanding your intent, you can do this much more easily with 如果我不误解您的意图,那么您可以轻松地做到这一点
var $x = $(".tabularData tr").filter(".odd, .even").first();
However, do you really need the "odd or even" test? 但是,您真的需要“奇数甚至偶数”测试吗? Since every row is either odd or even, it sounds like it would be much simpler to just do 由于每一行要么是奇数,要么是偶数,所以听起来好像要简单得多
var $x = $(".tabularData tr:first");
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.