我無法讓Jquery .closest()
正常工作。無法讓Jquery .closest()工作?
這裏是我的代碼,這很簡單,我看不出有任何理由不應該工作:
jQuery的
show:function(a,fx){
$('.more-content').hide();
$(a).toggle(function() {
t = $(this).closest(".more-content")
if (fx.match('show')) {
t.show()
};
if (fx.match('slide')) {
t.slideDown()
};
if (fx.match('fade')) {
t.fadeIn()
};
$(this).html('Less')
}, function() {
if (fx.match('show')) {
t.hide()
};
if (fx.match('slide')) {
t.slideUp()
};
if (fx.match('fade')) {
t.fadeOut()
};
$(this).html('More')
});
}
HTML
<p><strong class="goal">The Goal</strong><br />
To support those who are NEET <span class="more-content">We do this by providing education or training to enable said people to be...</span>
<span class="more">More</span>
<br /><br />
To build community cohesion in the local area. <span class="more-content">This will lead to a community where people have the opportunity...</span>
<span class="more">More</span>
</p>
困惑,所以任何幫助非常感謝,謝謝
確保你結束你的jQuery語句用';' – Mathletics 2012-01-13 19:54:26
並請出示您的標記;我們無法驗證您的選擇器/遍歷而不看到標記! – Mathletics 2012-01-13 19:55:07
更多的可能是'.more-content'不是錨標籤的祖先,因爲如果錨標籤是可見的,它必須是可見的。 '.closest'只用於選擇祖先,而不是兄弟姐妹。請閱讀文檔http://api.jquery.com/closest/ – 2012-01-13 19:59:01