为什么这有效: http://jsfiddle.net/4q5du/
而这则不然: http://jsfiddle.net/zcuYw/
我唯一要改变的是,在第二个中,我的目标是 div 内的链接,而在第一个中,我直接定位链接。为什么第二个不起作用?
$('div.more').hide()
$('a.showmemore').click(function(){
$(this).next('div').slideToggle()
})
对比
$('div.more').hide()
$('div.maurice a').click(function(){
$(this).next('div').slideToggle()
})
最佳答案
$('div.more').hide()
$('div.maurice a').click(function (e) {
e.preventDefault(); // As in your example, you're click on anchor so you
// you need to prevent default anchor behavior
$(this)
.parent() // jump to .maurice
.next('div') // got next div
.slideToggle() // show effect
})
关于jquery - 当定位 div 内的链接时,显示/隐藏文本不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18176193/