我有这样的东西:
HTML
<body>
<div>
<p>Text</p>
</div>
<body>
JQuery
$('div').click(function(){
$(this).find('p').fadeToggle('fast');
});
$('body').click(function(){
$('div').find('p').fadeOut();
});
如何防止点击前面的项目时点击后面的项目?
最佳答案
您可能需要event.stopPropagation()或者需要从 click
事件处理程序返回 false。
<强> Live Demo
$('div').click(function(event){
event.stopPropagation();
$(this).find('p').fadeToggle('fast');
});
Description: Prevents the event from bubbling up the DOM tree, preventing any parent handlers from being notified of the event.
关于javascript - 重叠项目上的单击功能,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20729244/