我正在尝试向多段添加阅读更多/阅读更少功能。
我使用以下 HTML 和 jquery。但是,如果我单击不同的“阅读更多”链接,它就无法正常工作。“多读”停留在“多读”,或多读少读的文字变得混乱。
谁能告诉我如何解决这个问题?
提前致谢。
<div id="section1">
<div class="toppara">
<img src="images/toh_texture1a.jpg" width="90" height="90" alt="pic" />
<p>Content 1. </p>
</div>
<div class="morepara">
<img src="images/plucchini_texture02.jpg" width="90" height="90" alt="pic" />
<p>
Content 1-a.
</p>
</div>
<p class="togglebutn">
<a href="#">LESE MER</a>
</p>
</div><!-- section 1 -->
<!-- section 2 -->
<div id="section2">
<div class="toppara">
<img src="images/dandelion.jpg" width="90" height="90" alt="pic" />
<p>Content 2. </p>
</div>
<div class="morepara">
<img src="images/toh_texture1a.jpg" width="90" height="90" />
<p>
Content 2-a.
</p>
</div>
<p class="togglebutn">
<a href="#">LESE MER</a>
</p>
</div><!-- section 2 -->
<!-- section 3 -->
<div id="section3">
<div class="toppara">
<img src="images/plucchini_texture02.jpg" width="90" height="90" />
<p>Content 3. </p>
</div>
<div class="morepara">
<img src="images/dandelion.jpg" width="90" height="90" />
<p>
Content 3-a.
</p>
</div>
<p class="togglebutn">
<a href="#">LESE MER</a>
</p>
</div><!-- section 3 -->
<!-- section 4 -->
<div id="section4">
<div class="toppara">
<img src="images/toh_texture1a.jpg" width="90" height="90" />
<p>Content 4. </p>
</div>
<div class="morepara">
<img src="images/plucchini_texture02.jpg" width="90" height="90" />
<p>
Content 4-a.
</p>
</div>
<p class="togglebutn">
<a href="#">LESE MER</a>
</p>
</div><!-- section 4 -->
<script language="javascript" type="text/javascript">
$(function() {
// set a variable Toggled to false
var Toggled=false;
// Toggle a paragraph
$('.togglebutn a').click(function(){
var $parentpara = $(this).parent().prev();
if(Toggled==false){$(this).html('<span class="readless">read less</span>'); Toggled=true;}
else{$(this).html('<span class="readmore">read more</span>');Toggled=false;}
$parentpara.toggle('slow');
return false;
});
});
</script>