0

jqueryに問題があります。私はいくつか持っています

ulliが閉じられた後のタグ

liがクリックされたときに特定のpタグのコンテンツを選択したい

ここに私のHTMLで

<div class="content">
      <p><span style="color: #d10018; font-family: Helvetica, Arial, sans-serif; font-size: 15pt; line-height: normal; text-align: left; background-color: #ffffff;">VALUES CREATE TRUST</span></p>
<h1><span style="font-size: 9pt;">From customer </span></h1>
<ul>
<li>Appreciations</li>
</ul>
<p style="margin-left: .75in;" class="ulptag">Your company culture is our groundwork. We select the candidates according to professional, objective criteria, but also pay attention that every candidate supplements the company/team best possible. Because pleasure at work increases the life quality of every individual.</p>
<p style="margin-left: .75in;" class="ulptag">With personal contact, we ensure that the special needs of our customers are fulfilled precisely.</p>
<p style="margin-left: .75in;" class="ulptag">Everybody benefits from our selection process. Candidates receive a comprehensive feedback with the results of the potential diagnostics. You as a company benefit from the appreciative handling of every candidate.</p>
<p>&nbsp;</p>
<ul>
<li>Structured procedure for enjoying mutual success.</li>
</ul>
<p style="margin-left: .75in;" class="ulptag"> successful decisions.</p>
<p style="margin-left: .75in;" class="ulptag">position.</p>
<p style="margin-left: .75in;" class="ulptag">every position.</p>
<p>&nbsp;</p>
<ul>
<li>Using innovations.</li>
</ul>
<p style="margin-left: .75in;" class="ulptag".n high demand also among competitors.</p>
<p style="margin-left: .75in;" class="ulptag">Advantage is assured by well-founded branch experience and knowledge of current developments in the respective markets.</p>
<p style="margin-left: .75in;">. our above-average dedication and effort.</p>


<p style="margin-left: .75in;" class="ulptag">&nbsp;</p>
    </div>

前もって感謝します

4

2 に答える 2

1
$(document).ready(function(){
    $("ul").nextAll('p').each(function(){
         $(this).click(function(){
              alert($(this).text());
         });
    });
});

こちらのhttp://jsfiddle.net/UMquF/をご覧ください。

于 2012-09-28T04:22:49.470 に答える
1
$(".content>ul").each(function() {
  $(this).click(function() {            
     console.log($(this).nextUntil(":not(p)").text());
  });
});

jsFiddle

更新:ここに説明があります

  • $("。content>ul")は、すべての "ul" elem.sを選択し、クリックイベントハンドラーを割り当てます。
  • 各イベントハンドラーで、このセレクター「:not(p)」を使用して非p要素が見つかるまで、すべての「次の」兄弟を選択します。nextUntilを参照してください
  • 兄弟を選んだ後、それらからテキストを抽出するだけです。
于 2012-09-28T04:52:29.593 に答える