2014-03-29 60 views
0
How to find the span text Achievements, QA , Dept having parent span Talk using Jquery. 

IM應該生成動態HTML像下面有不同的父跨度文本並保存LI>跨度值在數據庫jQuery的發現元素

<span class="chntxt">Talk(parent)</span> 

<div title="" class="elemenaryschool_chn chzn-container chzn-container-multi"> 

<ul class="chzn-choices"> 

<li seq="1" subseq="1" id="58" class="search-choice"> 
<span>Achievements</span> 
<a rel="3" class="search-choice-close" href="javascript:void(0)"></a></li> 

<li seq="1" subseq="2" id="59" class="search-choice"> 
<span>QA</span> 
<a rel="3" class="search-choice-close" href="javascript:void(0)"></a></li> 

<li seq="1" subseq="3" id="60" class="search-choice"> 
<span>Dept</span> 
<a rel="3" class="search-choice-close" href="javascript:void(0)"></a></li> 

<li class="search-field"><span contenteditable="true" style="width: 25px;"></span></li> 

</ul></div> 
+1

問題不清楚..需要重新編寫。 –

+0

嘗試從你的最後一個問題作出回答:[jQuery在ul li span中查找元素](http://stackoverflow.com/questions/22712072/jquery-find-element-in-ul-li-span) – Arka

回答

1

這裏是你如何可以自己選擇跨度。我假設你說你「有父母交談」,你想從那個起點穿過樹。以下是我想出了:

jQuery('.chntxt').on('click', function(){ 
    jQuery(this).nextAll().find('span').css('border', '1px solid red'); 
}); 

名爲.css()僅僅是顯示被選中的。你可以將它改爲.text()並使用.each()將它們全部存儲爲變量或數組或其他內容。

0

爲了使用jQuery找對象,你可以使用jQuery.find()

http://api.jquery.com/find/

$( 「跨度」).parent()。找到( 「李」)的.css( 「背景色」,「紅色」);