我无法让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