Jquery 忽略li中的第一项
我试图创建一个列出li class=“table”项的函数,这就是我到目前为止得到的结果Jquery 忽略li中的第一项,jquery,Jquery,我试图创建一个列出li class=“table”项的函数,这就是我到目前为止得到的结果 function getGuests(){ $('.child').each(function () { $(this).find("li").each(function () { var guest = $(this).html(); alert(guest); }); }); } <ul class="main"> <input type="button"
function getGuests(){
$('.child').each(function () {
$(this).find("li").each(function () {
var guest = $(this).html();
alert(guest);
});
});
}
<ul class="main">
<input type="button" class="addTable" value="Add Table">
<li class="table">
<ul class="child">
<li class="header">Table 1<input type="button" class="addGuest" value="Add Guest" ></li>
<li class="guest">example1</li>
<li class="guest">example2</li>
</ul>
</li>
</ul>
函数getGuests(){
$('.child')。每个(函数(){
$(this).find(“li”).each(函数(){
var guest=$(this.html();
警惕(客人);
});
});
}
-
-
表1
- 示例1
- 示例2
它读li class=“header”但是,我有办法忽略它吗?使用
:gt
选择器:
$(this).find("li:gt(0)").each(function () {
var guest = $(this).html();
alert(guest);
});
使用
:gt
选择器:
$(this).find("li:gt(0)").each(function () {
var guest = $(this).html();
alert(guest);
});
您可以使用
你可以使用
jQuery中最快的方法是:
$(this).find("li:not(.header)").each(function () {
var guest = $(this).html();
alert(guest);
jQuery中最快的方法是:
$(this).find("li:not(.header)").each(function () {
var guest = $(this).html();
alert(guest);
使用此功能
function getGuests(){
$('.child').each(function () {
$(this).find("li").not('.header').each(function () {
var guest = $(this).html();
alert(guest);
});
});
}
使用此功能
function getGuests(){
$('.child').each(function () {
$(this).find("li").not('.header').each(function () {
var guest = $(this).html();
alert(guest);
});
});
}
出于好奇,什么是gt?首先我听说了。阅读文档。
选择索引大于匹配集中索引的所有元素。
出于好奇,什么:gt?首先,我听说了。阅读文档。选择索引大于匹配集中索引的所有元素。