如何使用jquery获取ul li列表值

时间:2016-04-04 08:19:31

标签: jquery

我在<ul> s中有两个项目列表。我只是希望得到ul id sortable2

之一的所有项目
<ul id="sortable1" class="connectedSortable">
  <li class="ui-state-default">Item 1</li>
  <li class="ui-state-default">Item 2</li>
  <li class="ui-state-default">Item 3</li>
  <li class="ui-state-default">Item 4</li>
  <li class="ui-state-default">Item 5</li>
</ul>

<ul id="sortable2" class="connectedSortable" name="test">
  <li class="ui-state-highlight">Item 1</li>
  <li class="ui-state-highlight">Item 2</li>
  <li class="ui-state-highlight">Item 3</li>
  <li class="ui-state-highlight">Item 4</li>
  <li class="ui-state-highlight">Item 5</li>
</ul>

我正在尝试此代码,但它无法正常工作,因为我希望基于id的列表数据。我不知道如何实现它。

到目前为止,这是我的代码:

function myFunction() {
    var elementsLI = document.getElementsByTagName('li')
    var length = document.getElementsByTagName('li').length;
    for(var i = 0; i <= length ; ++i){
        alert(elementsLI[i].value);
    }
}

5 个答案:

答案 0 :(得分:2)

当您使用jquery时,您可以使用.map().val()/.value方法,只有表单元素可以获取输入,在您的情况下,您只需要.text()/.html()/.textContent/.innerHTML

&#13;
&#13;
var values = $("#sortable2 li").map(function() {
  return this.textContent.trim();
}).get();

$('pre').html(JSON.stringify(values, 0, 3))
&#13;
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<ul id="sortable2" class="connectedSortable" name="test">
  <li class="ui-state-highlight">Item 1</li>
  <li class="ui-state-highlight">Item 2</li>
  <li class="ui-state-highlight">Item 3</li>
  <li class="ui-state-highlight">Item 4</li>
  <li class="ui-state-highlight">Item 5</li>
</ul>
<pre></pre>
&#13;
&#13;
&#13;

答案 1 :(得分:1)

我的解决方案JQuery选择ul,然后选择每个li并获取文字值:

$($('.advancedSearchCheckBoxList')).each(function(){// id of ul
  var li = $(this).find('li')//get each li in ul
  li.each(function(){// id of ul
     labels.push( $(this).text() )
  })
})

labels=[]
$($('.advancedSearchCheckBoxList')).each(function(){// id of ul
  var li = $(this).find('li')//get each li in ul
  li.each(function(){// id of ul
     labels.push( $(this).text() )
  })
})
console.log( JSON.stringify( labels, null, 2) )
.advancedSearchCheckBoxList {
  list-style-type: none;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<ul class="advancedSearchCheckBoxList"><li><div class="advancedSearchCheckboxWrap"><input type="checkbox" name="fieldSelections[moods][]" value="1950's" id="moods1950's"></div><label class="advancedSearchLabel" for="moods1950's">1950's<span class="advancedSearchFacetCount">[3]</span></label></li><li><div class="advancedSearchCheckboxWrap"><input type="checkbox" name="fieldSelections[moods][]" value="1960's" id="moods1960's"></div><label class="advancedSearchLabel" for="moods1960's">1960's<span class="advancedSearchFacetCount">[9]</span></label></li><li><div class="advancedSearchCheckboxWrap"><input type="checkbox" name="fieldSelections[moods][]" value="1970's" id="moods1970's"></div><label class="advancedSearchLabel" for="moods1970's">1970's<span class="advancedSearchFacetCount">[54]</span></label></li><li><div class="advancedSearchCheckboxWrap"><input type="checkbox" name="fieldSelections[moods][]" value="1980's" id="moods1980's"></div><label class="advancedSearchLabel" for="moods1980's">1980's<span class="advancedSearchFacetCount">[44]</span></label></li><li><div class="advancedSearchCheckboxWrap"><input type="checkbox" name="fieldSelections[moods][]" value="1990's" id="moods1990's"></div><label class="advancedSearchLabel" for="moods1990's">1990's<span class="advancedSearchFacetCount">[24]</span></label></li><li><div class="advancedSearchCheckboxWrap"><input type="checkbox" name="fieldSelections[moods][]" value="Acapella" id="moodsAcapella"></div><label class="advancedSearchLabel" for="moodsAcapella">Acapella<span class="advancedSearchFacetCount">[4]</span></label></li><li><div class="advancedSearchCheckboxWrap"><input type="checkbox" name="fieldSelections[moods][]" value="Active" id="moodsActive"></div><label class="advancedSearchLabel" for="moodsActive">Active<span class="advancedSearchFacetCount">[384]</span></label></li><li><div class="advancedSearchCheckboxWrap"><input type="checkbox" name="fieldSelections[moods][]" value="Aggressive" id="moodsAggressive"></div><label class="advancedSearchLabel" for="moodsAggressive">Aggressive<span class="advancedSearchFacetCount">[1,173]</span></label></li><li><div class="advancedSearchCheckboxWrap"><input type="checkbox" name="fieldSelections[moods][]" value="Aggressive. Chaotic" id="moodsAggressive. Chaotic"></div><label class="advancedSearchLabel" for="moodsAggressive. Chaotic">Aggressive. Chaotic<span class="advancedSearchFacetCount">[2]</span></label></li><li><div class="advancedSearchCheckboxWrap"><input type="checkbox" name="fieldSelections[moods][]" value="Ambient" id="moodsAmbient"></div><label class="advancedSearchLabel" for="moodsAmbient">Ambient<span class="advancedSearchFacetCount">[130]</span></label></li><li><div class="advancedSearchCheckboxWrap"><input type="checkbox" name="fieldSelections[moods][]" value="Angry" id="moodsAngry"></div><label class="advancedSearchLabel" for="moodsAngry">Angry<span class="advancedSearchFacetCount">[44]</span></label></li><li><div class="advancedSearchCheckboxWrap"><input type="checkbox" name="fieldSelections[moods][]" value="Atmospheric" id="moodsAtmospheric"></div><label class="advancedSearchLabel" for="moodsAtmospheric">Atmospheric<span class="advancedSearchFacetCount">[280]</span></label></li><li><div class="advancedSearchCheckboxWrap"><input type="checkbox" name="fieldSelections[moods][]" value="Beautiful" id="moodsBeautiful"></div><label class="advancedSearchLabel" for="moodsBeautiful">Beautiful<span class="advancedSearchFacetCount">[48]</span></label></li><li><div class="advancedSearchCheckboxWrap"><input type="checkbox" name="fieldSelections[moods][]" value="Bouncy" id="moodsBouncy"></div><label class="advancedSearchLabel" for="moodsBouncy">Bouncy<span class="advancedSearchFacetCount">[311]</span></label></li><li><div class="advancedSearchCheckboxWrap"><input type="checkbox" name="fieldSelections[moods][]" value="Bright" id="moodsBright"></div><label class="advancedSearchLabel" for="moodsBright">Bright<span class="advancedSearchFacetCount">[208]</span></label></li><li><div class="advancedSearchCheckboxWrap"><input type="checkbox" name="fieldSelections[moods][]" value="Building" id="moodsBuilding"></div><label class="advancedSearchLabel" for="moodsBuilding">Building<span class="advancedSearchFacetCount">[745]</span></label></li><li><div class="advancedSearchCheckboxWrap"><input type="checkbox" name="fieldSelections[moods][]" value="Busy" id="moodsBusy"></div><label class="advancedSearchLabel" for="moodsBusy">Busy<span class="advancedSearchFacetCount">[53]</span></label></li><li><div class="advancedSearchCheckboxWrap"><input type="checkbox" name="fieldSelections[moods][]" value="Calm" id="moodsCalm"></div><label class="advancedSearchLabel" for="moodsCalm">Calm<span class="advancedSearchFacetCount">[510]</span></label></li><li><div class="advancedSearchCheckboxWrap"><input type="checkbox" name="fieldSelections[moods][]" value="Chaotic" id="moodsChaotic"></div><label class="advancedSearchLabel" for="moodsChaotic">Chaotic<span class="advancedSearchFacetCount">[76]</span></label></li><li><div class="advancedSearchCheckboxWrap"><input type="checkbox" name="fieldSelections[moods][]" value="Chase" id="moodsChase"></div><label class="advancedSearchLabel" for="moodsChase">Chase<span class="advancedSearchFacetCount">[13]</span></label></li><li><div class="advancedSearchCheckboxWrap"><input type="checkbox" name="fieldSelections[moods][]" value="Childish" id="moodsChildish"></div><label class="advancedSearchLabel" for="moodsChildish">Childish<span class="advancedSearchFacetCount">[8]</span></label></li><li><div class="advancedSearchCheckboxWrap"><input type="checkbox" name="fieldSelections[moods][]" value="Chill Out" id="moodsChill Out"></div><label class="advancedSearchLabel" for="moodsChill Out">Chill Out<span class="advancedSearchFacetCount">[2]</span></label></li><li><div class="advancedSearchCheckboxWrap"><input type="checkbox" name="fieldSelections[moods][]" value="Chillout" id="moodsChillout"></div><label class="advancedSearchLabel" for="moodsChillout">Chillout<span class="advancedSearchFacetCount">[51]</span></label></li><li><div class="advancedSearchCheckboxWrap"><input type="checkbox" name="fieldSelections[moods][]" value="Confident" id="moodsConfident"></div><label class="advancedSearchLabel" for="moodsConfident">Confident<span class="advancedSearchFacetCount">[830]</span></label></li><li><div class="advancedSearchCheckboxWrap"><input type="checkbox" name="fieldSelections[moods][]" value="Cozy" id="moodsCozy"></div><label class="advancedSearchLabel" for="moodsCozy">Cozy<span class="advancedSearchFacetCount">[15]</span></label></li><li><div class="advancedSearchCheckboxWrap"><input type="checkbox" name="fieldSelections[moods][]" value="Dance" id="moodsDance"></div><label class="advancedSearchLabel" for="moodsDance">Dance<span class="advancedSearchFacetCount">[151]</span></label></li><li><div class="advancedSearchCheckboxWrap"><input type="checkbox" name="fieldSelections[moods][]" value="Danceable" id="moodsDanceable"></div><label class="advancedSearchLabel" for="moodsDanceable">Danceable<span class="advancedSearchFacetCount">[793]</span></label></li><li><div class="advancedSearchCheckboxWrap"><input type="checkbox" name="fieldSelections[moods][]" value="Dancebale" id="moodsDancebale"></div><label class="advancedSearchLabel" for="moodsDancebale">Dancebale<span class="advancedSearchFacetCount">[3]</span></label></li><li><div class="advancedSearchCheckboxWrap"><input type="checkbox" name="fieldSelections[moods][]" value="Dark" id="moodsDark"></div><label class="advancedSearchLabel" for="moodsDark">Dark<span class="advancedSearchFacetCount">[382]</span></label></li><li><div class="advancedSearchCheckboxWrap"><input type="checkbox" name="fieldSelections[moods][]" value="Despair" id="moodsDespair"></div><label class="advancedSearchLabel" for="moodsDespair">Despair<span class="advancedSearchFacetCount">[35]</span></label></li><li><div class="advancedSearchCheckboxWrap"><input type="checkbox" name="fieldSelections[moods][]" value="Dreamy" id="moodsDreamy"></div><label class="advancedSearchLabel" for="moodsDreamy">Dreamy<span class="advancedSearchFacetCount">[397]</span></label></li><li><div class="advancedSearchCheckboxWrap"><input type="checkbox" name="fieldSelections[moods][]" value="Driving" id="moodsDriving"></div><label class="advancedSearchLabel" for="moodsDriving">Driving<span class="advancedSearchFacetCount">[534]</span></label></li><li><div class="advancedSearchCheckboxWrap"><input type="checkbox" name="fieldSelections[moods][]" value="Easy Listening" id="moodsEasy Listening"></div><label class="advancedSearchLabel" for="moodsEasy Listening">Easy Listening<span class="advancedSearchFacetCount">[1,112]</span></label></li><li><div class="advancedSearchCheckboxWrap"><input type="checkbox" name="fieldSelections[moods][]" value="Eerie" id="moodsEerie"></div><label class="advancedSearchLabel" for="moodsEerie">Eerie<span class="advancedSearchFacetCount">[29]</span></label></li><li><div class="advancedSearchCheckboxWrap"><input type="checkbox" name="fieldSelections[moods][]" value="Electric" id="moodsElectric"></div><label class="advancedSearchLabel" for="moodsElectric">Electric<span class="advancedSearchFacetCount">[2]</span></label></li><li><div class="advancedSearchCheckboxWrap"><input type="checkbox" name="fieldSelections[moods][]" value="Electronic" id="moodsElectronic"></div><label class="advancedSearchLabel" for="moodsElectronic">Electronic<span class="advancedSearchFacetCount">[246]</span></label></li><li><div class="advancedSearchCheckboxWrap"><input type="checkbox" name="fieldSelections[moods][]" value="Elegant" id="moodsElegant"></div><label class="advancedSearchLabel" for="moodsElegant">Elegant<span class="advancedSearchFacetCount">[30]</span></label></li><li><div class="advancedSearchCheckboxWrap"><input type="checkbox" name="fieldSelections[moods][]" value="Emotional" id="moodsEmotional"></div><label class="advancedSearchLabel" for="moodsEmotional">Emotional<span class="advancedSearchFacetCount">[235]</span></label></li><li><div class="advancedSearchCheckboxWrap"><input type="checkbox" name="fieldSelections[moods][]" value="Energetic" id="moodsEnergetic"></div><label class="advancedSearchLabel" for="moodsEnergetic">Energetic<span class="advancedSearchFacetCount">[2,284]</span></label></li><li><div class="advancedSearchCheckboxWrap"><input type="checkbox" name="fieldSelections[moods][]" value="Epic" id="moodsEpic"></div><label class="advancedSearchLabel" for="moodsEpic">Epic<span class="advancedSearchFacetCount">[33]</span></label></li><li><div class="advancedSearchCheckboxWrap"><input type="checkbox" name="fieldSelections[moods][]" value="Epic. Aggressive" id="moodsEpic. Aggressive"></div><label class="advancedSearchLabel" for="moodsEpic. Aggressive">Epic. Aggressive<span class="advancedSearchFacetCount">[1]</span></label></li><li><div class="advancedSearchCheckboxWrap"><input type="checkbox" name="fieldSelections[moods][]" value="Ethnic" id="moodsEthnic"></div><label class="advancedSearchLabel" for="moodsEthnic">Ethnic<span class="advancedSearchFacetCount">[28]</span></label></li><li><div class="advancedSearchCheckboxWrap"><input type="checkbox" name="fieldSelections[moods][]" value="Experimental" id="moodsExperimental"></div><label class="advancedSearchLabel" for="moodsExperimental">Experimental<span class="advancedSearchFacetCount">[19]</span></label></li><li><div class="advancedSearchCheckboxWrap"><input type="checkbox" name="fieldSelections[moods][]" value="Fast" id="moodsFast"></div><label class="advancedSearchLabel" for="moodsFast">Fast<span class="advancedSearchFacetCount">[103]</span></label></li><li><div class="advancedSearchCheckboxWrap"><input type="checkbox" name="fieldSelections[moods][]" value="Feel Good" id="moodsFeel Good"></div><label class="advancedSearchLabel" for="moodsFeel Good">Feel Good<span class="advancedSearchFacetCount">[531]</span></label></li><li><div class="advancedSearchCheckboxWrap"><input type="checkbox" name="fieldSelections[moods][]" value="Free" id="moodsFree"></div><label class="advancedSearchLabel" for="moodsFree">Free<span class="advancedSearchFacetCount">[75]</span></label></li><li><div class="advancedSearchCheckboxWrap"><input type="checkbox" name="fieldSelections[moods][]" value="Funky" id="moodsFunky"></div><label class="advancedSearchLabel" for="moodsFunky">Funky<span class="advancedSearchFacetCount">[166]</span></label></li><li><div class="advancedSearchCheckboxWrap"><input type="checkbox" name="fieldSelections[moods][]" value="Futuristic" id="moodsFuturistic"></div><label class="advancedSearchLabel" for="moodsFuturistic">Futuristic<span class="advancedSearchFacetCount">[172]</span></label></li><li><div class="advancedSearchCheckboxWrap"><input type="checkbox" name="fieldSelections[moods][]" value="Gangster" id="moodsGangster"></div><label class="advancedSearchLabel" for="moodsGangster">Gangster<span class="advancedSearchFacetCount">[239]</span></label></li><li><div class="advancedSearchCheckboxWrap"><input type="checkbox" name="fieldSelections[moods][]" value="Gentle" id="moodsGentle"></div><label class="advancedSearchLabel" for="moodsGentle">Gentle<span class="advancedSearchFacetCount">[240]</span></label></li><li><div class="advancedSearchCheckboxWrap"><input type="checkbox" name="fieldSelections[moods][]" value="Goovy" id="moodsGoovy"></div><label class="advancedSearchLabel" for="moodsGoovy">Goovy<span class="advancedSearchFacetCount">[4]</span></label></li><li><div class="advancedSearchCheckboxWrap"><input type="checkbox" name="fieldSelections[moods][]" value="Gritty" id="moodsGritty"></div><label class="advancedSearchLabel" for="moodsGritty">Gritty<span class="advancedSearchFacetCount">[141]</span></label></li><li><div class="advancedSearchCheckboxWrap"><input type="checkbox" name="fieldSelections[moods][]" value="Groovy" id="moodsGroovy"></div><label class="advancedSearchLabel" for="moodsGroovy">Groovy<span class="advancedSearchFacetCount">[412]</span></label></li><li><div class="advancedSearchCheckboxWrap"><input type="checkbox" name="fieldSelections[moods][]" value="Happy" id="moodsHappy"></div><label class="advancedSearchLabel" for="moodsHappy">Happy<span class="advancedSearchFacetCount">[868]</span></label></li><li><div class="advancedSearchCheckboxWrap"><input type="checkbox" name="fieldSelections[moods][]" value="Heartbreak" id="moodsHeartbreak"></div><label class="advancedSearchLabel" for="moodsHeartbreak">Heartbreak<span class="advancedSearchFacetCount">[28]</span></label></li><li><div class="advancedSearchCheckboxWrap"><input type="checkbox" name="fieldSelections[moods][]" value="Heavy" id="moodsHeavy"></div><label class="advancedSearchLabel" for="moodsHeavy">Heavy<span class="advancedSearchFacetCount">[192]</span></label></li><li><div class="advancedSearchCheckboxWrap"><input type="checkbox" name="fieldSelections[moods][]" value="Humorous" id="moodsHumorous"></div><label class="advancedSearchLabel" for="moodsHumorous">Humorous<span class="advancedSearchFacetCount">[256]</span></label></li><li><div class="advancedSearchCheckboxWrap"><input type="checkbox" name="fieldSelections[moods][]" value="Jazzy" id="moodsJazzy"></div><label class="advancedSearchLabel" for="moodsJazzy">Jazzy<span class="advancedSearchFacetCount">[45]</span></label></li><li><div class="advancedSearchCheckboxWrap"><input type="checkbox" name="fieldSelections[moods][]" value="Laidback" id="moodsLaidback"></div><label class="advancedSearchLabel" for="moodsLaidback">Laidback<span class="advancedSearchFacetCount">[4]</span></label></li><li><div class="advancedSearchCheckboxWrap"><input type="checkbox" name="fieldSelections[moods][]" value="Laid Back" id="moodsLaid Back"></div><label class="advancedSearchLabel" for="moodsLaid Back">Laid Back<span class="advancedSearchFacetCount">[211]</span></label></li><li><div class="advancedSearchCheckboxWrap"><input type="checkbox" name="fieldSelections[moods][]" value="Latin" id="moodsLatin"></div><label class="advancedSearchLabel" for="moodsLatin">Latin<span class="advancedSearchFacetCount">[3]</span></label></li><li><div class="advancedSearchCheckboxWrap"><input type="checkbox" name="fieldSelections[moods][]" value="Light" id="moodsLight"></div><label class="advancedSearchLabel" for="moodsLight">Light<span class="advancedSearchFacetCount">[98]</span></label></li><li><div class="advancedSearchCheckboxWrap"><input type="checkbox" name="fieldSelections[moods][]" value="Love" id="moodsLove"></div><label class="advancedSearchLabel" for="moodsLove">Love<span class="advancedSearchFacetCount">[44]</span></label></li><li><div class="advancedSearchCheckboxWrap"><input type="checkbox" name="fieldSelections[moods][]" value="Lush" id="moodsLush"></div><label class="advancedSearchLabel" for="moodsLush">Lush<span class="advancedSearchFacetCount">[44]</span></label></li><li><div class="advancedSearchCheckboxWrap"><input type="checkbox" name="fieldSelections[moods][]" value="Melancholic" id="moodsMelancholic"></div><label class="advancedSearchLabel" for="moodsMelancholic">Melancholic<span class="advancedSearchFacetCount">[1,141]</span></label></li><li><div class="advancedSearchCheckboxWrap"><input type="checkbox" name="fieldSelections[moods][]" value="Melodic" id="moodsMelodic"></div><label class="advancedSearchLabel" for="moodsMelodic">Melodic<span class="advancedSearchFacetCount">[201]</span></label></li><li><div class="advancedSearchCheckboxWrap"><input type="checkbox" name="fieldSelections[moods][]" value="Melody" id="moodsMelody"></div><label class="advancedSearchLabel" for="moodsMelody">Melody<span class="advancedSearchFacetCount">[1]</span></label></li><li><div class="advancedSearchCheckboxWrap"><input type="checkbox" name="fieldSelections[moods][]" value="Montage" id="moodsMontage"></div><label class="advancedSearchLabel" for="moodsMontage">Montage<span class="advancedSearchFacetCount">[1]</span></label></li><li><div class="advancedSearchCheckboxWrap"><input type="checkbox" name="fieldSelections[moods][]" value="Motivating" id="moodsMotivating"></div><label class="advancedSearchLabel" for="moodsMotivating">Motivating<span class="advancedSearchFacetCount">[34]</span></label></li><li><div class="advancedSearchCheckboxWrap"><input type="checkbox" name="fieldSelections[moods][]" value="Mysterious" id="moodsMysterious"></div><label class="advancedSearchLabel" for="moodsMysterious">Mysterious<span class="advancedSearchFacetCount">[157]</span></label></li><li><div class="advancedSearchCheckboxWrap"><input type="checkbox" name="fieldSelections[moods][]" value="Mystersious" id="moodsMystersious"></div><label class="advancedSearchLabel" for="moodsMystersious">Mystersious<span class="advancedSearchFacetCount">[1]</span></label></li><li><div class="advancedSearchCheckboxWrap"><input type="checkbox" name="fieldSelections[moods][]" value="Pain" id="moodsPain"></div><label class="advancedSearchLabel" for="moodsPain">Pain<span class="advancedSearchFacetCount">[16]</span></label></li><li><div class="advancedSearchCheckboxWrap"><input type="checkbox" name="fieldSelections[moods][]" value="Party" id="moodsParty"></div><label class="advancedSearchLabel" for="moodsParty">Party<span class="advancedSearchFacetCount">[71]</span></label></li><li><div class="advancedSearchCheckboxWrap"><input type="checkbox" name="fieldSelections[moods][]" value="Positive" id="moodsPositive"></div><label class="advancedSearchLabel" for="moodsPositive">Positive<span class="advancedSearchFacetCount">[133]</span></label></li><li><div class="advancedSearchCheckboxWrap"><input type="checkbox" name="fieldSelections[moods][]" value="Quirky" id="moodsQuirky"></div><label class="advancedSearchLabel" for="moodsQuirky">Quirky<span class="advancedSearchFacetCount">[94]</span></label></li><li><div class="advancedSearchCheckboxWrap"><input type="checkbox" name="fieldSelections[moods][]" value="Relaxed" id="moodsRelaxed"></div><label class="advancedSearchLabel" for="moodsRelaxed">Relaxed<span class="advancedSearchFacetCount">[397]</span></label></li><li><div class="advancedSearchCheckboxWrap"><input type="checkbox" name="fieldSelections[moods][]" value="Rhythmic" id="moodsRhythmic"></div><label class="advancedSearchLabel" for="moodsRhythmic">Rhythmic<span class="advancedSearchFacetCount">[731]</span></label></li><li><div class="advancedSearchCheckboxWrap"><input type="checkbox" name="fieldSelections[moods][]" value="Sad" id="moodsSad"></div><label class="advancedSearchLabel" for="moodsSad">Sad<span class="advancedSearchFacetCount">[104]</span></label></li><li><div class="advancedSearchCheckboxWrap"><input type="checkbox" name="fieldSelections[moods][]" value="Seductive" id="moodsSeductive"></div><label class="advancedSearchLabel" for="moodsSeductive">Seductive<span class="advancedSearchFacetCount">[320]</span></label></li><li><div class="advancedSearchCheckboxWrap"><input type="checkbox" name="fieldSelections[moods][]" value="Sensual" id="moodsSensual"></div><label class="advancedSearchLabel" for="moodsSensual">Sensual<span class="advancedSearchFacetCount">[65]</span></label></li><li><div class="advancedSearchCheckboxWrap"><input type="checkbox" name="fieldSelections[moods][]" value="Sentimental" id="moodsSentimental"></div><label class="advancedSearchLabel" for="moodsSentimental">Sentimental<span class="advancedSearchFacetCount">[295]</span></label></li><li><div class="advancedSearchCheckboxWrap"><input type="checkbox" name="fieldSelections[moods][]" value="Serious" id="moodsSerious"></div><label class="advancedSearchLabel" for="moodsSerious">Serious<span class="advancedSearchFacetCount">[54]</span></label></li><li><div class="advancedSearchCheckboxWrap"><input type="checkbox" name="fieldSelections[moods][]" value="Short" id="moodsShort"></div><label class="advancedSearchLabel" for="moodsShort">Short<span class="advancedSearchFacetCount">[7]</span></label></li><li><div class="advancedSearchCheckboxWrap"><input type="checkbox" name="fieldSelections[moods][]" value="Slow" id="moodsSlow"></div><label class="advancedSearchLabel" for="moodsSlow">Slow<span class="advancedSearchFacetCount">[96]</span></label></li><li><div class="advancedSearchCheckboxWrap"><input type="checkbox" name="fieldSelections[moods][]" value="Smooth" id="moodsSmooth"></div><label class="advancedSearchLabel" for="moodsSmooth">Smooth<span class="advancedSearchFacetCount">[170]</span></label></li><li><div class="advancedSearchCheckboxWrap"><input type="checkbox" name="fieldSelections[moods][]" value="Soft" id="moodsSoft"></div><label class="advancedSearchLabel" for="moodsSoft">Soft<span class="advancedSearchFacetCount">[36]</span></label></li><li><div class="advancedSearchCheckboxWrap"><input type="checkbox" name="fieldSelections[moods][]" value="Sophisticated" id="moodsSophisticated"></div><label class="advancedSearchLabel" for="moodsSophisticated">Sophisticated<span class="advancedSearchFacetCount">[45]</span></label></li><li><div class="advancedSearchCheckboxWrap"><input type="checkbox" name="fieldSelections[moods][]" value="Soulful" id="moodsSoulful"></div><label class="advancedSearchLabel" for="moodsSoulful">Soulful<span class="advancedSearchFacetCount">[354]</span></label></li><li><div class="advancedSearchCheckboxWrap"><input type="checkbox" name="fieldSelections[moods][]" value="Sparse" id="moodsSparse"></div><label class="advancedSearchLabel" for="moodsSparse">Sparse<span class="advancedSearchFacetCount">[129]</span></label></li><li><div class="advancedSearchCheckboxWrap"><input type="checkbox" name="fieldSelections[moods][]" value="Speaking" id="moodsSpeaking"></div><label class="advancedSearchLabel" for="moodsSpeaking">Speaking<span class="advancedSearchFacetCount">[28]</span></label></li><li><div class="advancedSearchCheckboxWrap"><input type="checkbox" name="fieldSelections[moods][]" value="Stong" id="moodsStong"></div><label class="advancedSearchLabel" for="moodsStong">Stong<span class="advancedSearchFacetCount">[4]</span></label></li><li><div class="advancedSearchCheckboxWrap"><input type="checkbox" name="fieldSelections[moods][]" value="Stressful" id="moodsStressful"></div><label class="advancedSearchLabel" for="moodsStressful">Stressful<span class="advancedSearchFacetCount">[647]</span></label></li><li><div class="advancedSearchCheckboxWrap"><input type="checkbox" name="fieldSelections[moods][]" value="Strong" id="moodsStrong"></div><label class="advancedSearchLabel" for="moodsStrong">Strong<span class="advancedSearchFacetCount">[124]</span></label></li><li><div class="advancedSearchCheckboxWrap"><input type="checkbox" name="fieldSelections[moods][]" value="Tender" id="moodsTender"></div><label class="advancedSearchLabel" for="moodsTender">Tender<span class="advancedSearchFacetCount">[95]</span></label></li><li><div class="advancedSearchCheckboxWrap"><input type="checkbox" name="fieldSelections[moods][]" value="Tense" id="moodsTense"></div><label class="advancedSearchLabel" for="moodsTense">Tense<span class="advancedSearchFacetCount">[64]</span></label></li><li><div class="advancedSearchCheckboxWrap"><input type="checkbox" name="fieldSelections[moods][]" value="Upbeat" id="moodsUpbeat"></div><label class="advancedSearchLabel" for="moodsUpbeat">Upbeat<span class="advancedSearchFacetCount">[525]</span></label></li><li><div class="advancedSearchCheckboxWrap"><input type="checkbox" name="fieldSelections[moods][]" value="Uplifting" id="moodsUplifting"></div><label class="advancedSearchLabel" for="moodsUplifting">Uplifting<span class="advancedSearchFacetCount">[226]</span></label></li><li><div class="advancedSearchCheckboxWrap"><input type="checkbox" name="fieldSelections[moods][]" value="Uptempo" id="moodsUptempo"></div><label class="advancedSearchLabel" for="moodsUptempo">Uptempo<span class="advancedSearchFacetCount">[93]</span></label></li><li><div class="advancedSearchCheckboxWrap"><input type="checkbox" name="fieldSelections[moods][]" value="Warm" id="moodsWarm"></div><label class="advancedSearchLabel" for="moodsWarm">Warm<span class="advancedSearchFacetCount">[105]</span></label></li><li><div class="advancedSearchCheckboxWrap"><input type="checkbox" name="fieldSelections[moods][]" value="Whimsical" id="moodsWhimsical"></div><label class="advancedSearchLabel" for="moodsWhimsical">Whimsical<span class="advancedSearchFacetCount">[39]</span></label></li><li><div class="advancedSearchCheckboxWrap"><input type="checkbox" name="fieldSelections[moods][]" value="Wild" id="moodsWild"></div><label class="advancedSearchLabel" for="moodsWild">Wild<span class="advancedSearchFacetCount">[14]</span></label></li><li><div class="advancedSearchCheckboxWrap"><input type="checkbox" name="fieldSelections[moods][]" value="Youthful" id="moodsYouthful"></div><label class="advancedSearchLabel" for="moodsYouthful">Youthful<span class="advancedSearchFacetCount">[35]</span></label></li></ul>

答案 2 :(得分:0)

使用循环:

var values =[];

$('.ui-state-highlight').each(function(i,v){
  values.push($(v).text());
});

答案 3 :(得分:0)

&#13;
&#13;
$('#sortable2').each(function(){// id of ul
  var li = $(this).find('li')//get each li in ul

console.log(li.text())//get text of each li


})
&#13;
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<ul id="sortable1" class="connectedSortable">
  <li class="ui-state-default">Item 1</li>
  <li class="ui-state-default">Item 2</li>
  <li class="ui-state-default">Item 3</li>
  <li class="ui-state-default">Item 4</li>
  <li class="ui-state-default">Item 5</li>
</ul>

<ul id="sortable2" class="connectedSortable" name="test">
  <li class="ui-state-highlight">Item 1</li>
  <li class="ui-state-highlight">Item 2</li>
  <li class="ui-state-highlight">Item 3</li>
  <li class="ui-state-highlight">Item 4</li>
  <li class="ui-state-highlight">Item 5</li>
</ul>
&#13;
&#13;
&#13;

你就是这样做的

答案 4 :(得分:0)

如果您使用的是jQuery,请使用.each()

// on ready select all li in ul with id='sortable2'
jQuery(document).ready(function(){
    jQuery('#sortable2 li').each(function(){
        console.log($(this).text()); //prints each li text value in console
    });     

});

jQuery(document).ready(function() {
  jQuery('#sortable2 li').each(function() {
    console.log($(this).text()); //prints each li text value in console
  });

});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<ul id="sortable2" class="connectedSortable" name="test">
  <li class="ui-state-highlight">Item 1</li>
  <li class="ui-state-highlight">Item 2</li>
  <li class="ui-state-highlight">Item 3</li>
  <li class="ui-state-highlight">Item 4</li>
  <li class="ui-state-highlight">Item 5</li>
</ul>