2012-01-25 122 views
2

我有T他下面的列表項:如何使用jQuery獲取列表項目中的跨文本?

<li class="item" id="44"> 
    <div class="name">Bogstadveien</div> 
    <div> 
    <span class="city">Oslo</span>, 
    <span class="country">Norway</span> 
    </div> 
</li> 

一旦點擊列表中的項目,我運行腳本:

var list_item = jQuery(this); 
var guide_id = list_item.attr('id'); 

如何獲取城市和國家價值觀?
我試過使用find,closestnext,但我沒有正確使用它們。

回答

1
var list_item = jQuery(this); 
var guide_id = list_item.attr('id'); 
var city = jQuery('span.city', list_item).text(); 
var country = jQuery('span.country', list_item).text(); 
1

能找到縣和城市使用發現它後,選擇從範圍文找到方法

list_item.find('.city').text() 
list_item.find('.country').text() 
相關問題