如何更改我的代码,当我多次单击一个特定read more
的并且slideToggle
每次读取更多/更少并显示/隐藏内容时,函数都会更改它,其他人会留下来read more
,但即便如此,当我点击其他链接时read more
,旧的slideUp和新的使用slideToggle
功能slideDown。
我的 HTML
<!-- === h1 === -->
<h1>Lorem ipsum dolor sit amet</h1>
<p>Ut enim ad minim veniam, quis nostrud exercitation.</p>
<p class="more">Duis aute irure dolor in reprehenderit in voluptate.</p>
<a class="read_more">... Read More</a>
<!-- === h2 === -->
<h2>Consectetur adipisicing elit</h2>
<p>On the other hand, we denounce with righteous.</p>
<p class="more">Gemoralized by the charms of pleasure of the moment.</p>
<a class="read_more">... Read More</a>
<!-- === h3 === -->
<h3>Sed do eiusmod tempor incididunt</h3>
<p>The wise man therefore always holds.</p>
<p class="more">Et harum quidem rerum facilis est et expedita distinctio.</p>
<a class="read_more">... Read More</a>
我的jQuery
var rm = $(".read_more"),
moreText = "... Read More",
lessText = "... Read Less";
rm.click(function () {
rm.text(moreText);
var $this = $(this);
var more = $this.text($this.text() == moreText ? lessText : moreText).prev(".more").slideToggle("normal");
$('.more').not(more).slideUp();
});