0

我对 jquery 有一些问题。我有一些

每个ul li 关闭后的标签

我想在点击 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 回答