在body点击,我需要滑动,这是滑动使用按钮点击(slideToggle)



我是Jquery的初学者。我在一个按钮上使用简单的滑动切换。最初,我把div在显示无,当我点击按钮,我使用滑动切换功能。它工作得很好。但是当我点击身体,我需要滑动(显示:无)以及按钮的点击也。我尝试了$('body:not(element)')点击函数,它不适合我。请帮我解决一下。

查看正常的滑动功能SlideToggle fiddle

这个小提琴,我试过但不工作尝试小提琴

$("#legendButton").click(function(){
    $("#slidetooglelegends").slideToggle("slow");
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<div id="LegendSlideSection">
	<div id="slidetooglelegends" style="width:200px;height:100px;border:1px solid #a3a3a3;background:#fff;display:none;">
		   hello slide
	</div>
	<button id="legendButton" class="btn btn-primary">Legend</button>
</div>

问题是,当你点击滑动按钮时,你也在技术上点击主体,因为它们相互重叠。你应该停止事件冒泡(如果你愿意的话),这样它只执行第一个捕获的事件,而不委托给其他事件处理程序。

这可以通过

实现
event.stopPropagation();

见下面的jsFiddle

$("#legendButton").click(function(event){
    event.stopPropagation();
    $("#slidetooglelegends").slideToggle("slow");
});
$("body:not(#legendButton)").click(function(){
    $("#slidetooglelegends").slideUp("slow");
});

我很难理解你的问题。

根据我对你问题的理解,我在这里给出了一个答案。

希望对你有帮助。

<div id="LegendSlideSection">
    <div id="slidetooglelegends" style="width:200px;height:100px;border:1px solid #a3a3a3;background:#fff;display:none;">
           hello slide
    </div>
    <button id="legendButton" class="btn btn-primary">Legend</button>
</div>
JQUERY

$("#legendButton").click(function(){
    $("#slidetooglelegends").slideToggle("slow");
});
$("#legendButton").blur(function(){
    $("#slidetooglelegends").slideToggle("slow");
});

提琴在这里

最新更新