你好朋友,我是jQuery
上的新朋友,並試圖做出切換效果。我的代碼工作正常,但我也想在其切換文本請檢查下面的代碼使用jQuery點擊事件
腳本
$('.read_more_list').click(function() {
$(".design_list").slideToggle();
if ($(this).children('a').html() == 'more') {
$(this).children('a').html('less');
}
if ($(this).children('a').html() == 'less') {
$(this).children('a').html('more');
}
})
HTML
<ul class="design_list" style="display: none;">
<li><a href="#">eCommerce</a></li>
<li><a href="#">Display Creatives</a></li>
<li><a href="#">Logo Design Services</a></li>
<li><a href="#">Microsites</a></li>
</ul>
<div class="read_more_list"><a href="javascript:void(0);">more</a></div>
我要上more
當用戶點擊那麼它會轉換成less
,當用戶再次點擊它時,它會變成more
請幫我謝謝朋友提前... :))
爲什麼要那樣做'$( 'A',這一點)'? 'this'已經是主播:) –
read_more_list是div,主播是它的後代 – Adil
是的,但點擊事件委託給'.read_more_list',所以'this'已經是主播了。 –