Javascript 如果在内部单击,则不应关闭下拉菜单
我将面板放在引导下拉列表中,但当我在面板中单击时,下拉列表消失了。我得到了很多关于stackoverflow的解决方案,但对我来说不起作用。如何防止面板在单击内部时消失。请在此处输入代码Javascript 如果在内部单击,则不应关闭下拉菜单,javascript,jquery,html,twitter-bootstrap,Javascript,Jquery,Html,Twitter Bootstrap,我将面板放在引导下拉列表中,但当我在面板中单击时,下拉列表消失了。我得到了很多关于stackoverflow的解决方案,但对我来说不起作用。如何防止面板在单击内部时消失。请在此处输入代码 尝试这样做:如果你点击主体,它会检查父类;如果你点击下拉列表,如果父类有类。下拉列表parentclass则下拉列表不会关闭 $('body').click(function(event){ if ($(event.target).parent('.dropdown-parentclass').size
尝试这样做:如果你点击主体,它会检查父类;如果你点击下拉列表,如果父类有类。下拉列表parentclass则下拉列表不会关闭
$('body').click(function(event){
if ($(event.target).parent('.dropdown-parentclass').size()>0) {
return false;
}
});
尝试使用下面的代码。只有在您单击容器外侧时,它才会关闭下拉列表
$(document).on("mouseup", function (e) {
var container = $(".panel");
if (!container.is(e.target) // if the target of the click isn't the container
&& container.has(e.target).length === 0) // nor a descendant of the container
{
container.hide();
}
else {
}
});
你能发布一个JSFIDLE吗?上面的解决方案对我不起作用。如果您需要更多信息,请告诉我。上述解决方案不适用于我。如果你需要更多信息,请告诉我。
$(document).on("mouseup", function (e) {
var container = $(".panel");
if (!container.is(e.target) // if the target of the click isn't the container
&& container.has(e.target).length === 0) // nor a descendant of the container
{
container.hide();
}
else {
}
});