捕获元素jquery外部的mousedown事件
capture mousedown event outside of an element jquery
var onEnableHelpCheckChange = function() {
// Checking weather checkbox is checked
if ($("#enable-help").prop('checked') === true) {
$('#nav-help-img').attr('src','/assets/images/help-1.png');
appendPreviousImages();
// bind custom context menu
$('#helpDiv').on("mousedown", function (event) {
if(isAnyPopOver2Visible){
if(!$(this).closest('#popover-output-div').length){
$('.helpBtn').popover('hide');
}
isAnyPopOver2Visible = false;
}
});
}
};
<div class="popover-output popover font-size-9pt" id="popover-output-div">
<label id="lbl-output-help"></label>
<textarea class="resize-none font-size-9pt width-400px" rows="6" id="txt-output-help" hidden></textarea>
<div class="row font-size-8pt popover-footer">
<a href="javascript:void(0);" id="btn-edit" onclick="BusinessPortal.Help.editHelpText();">Edit</a>
<a class="padding-left-10px" href="javascript:void(0);" id="btn-remove" onclick="BusinessPortal.Help.removeHelpPopover();">Remove</a>
<a href="javascript:void(0);" id="editable-save" onclick="BusinessPortal.Help.saveEditedHelpText();" hidden>Save</a>
</div>
</div>
我有下面的代码来隐藏popover和按钮。但问题是,即使我点击弹出窗口上的按钮,它也会隐藏起来。
我想做的是当鼠标放下时显示popover,并用鼠标放下事件隐藏popover。但当我点击popover时,它不应该隐藏。
$('#helpDiv').on("mousedown", function (event) {
$('.helpBtn').popover('hide');
});
您可以使用.closest()
和弹出元素选择器来检查是否在弹出窗口中单击。如果不是,则只隐藏弹出窗口:
$('#helpDiv').on("mousedown", function (e) {
if(!$(e.target).closest('#popover-output-div').length)
$('.helpBtn').popover('hide');
});
相关文章:
- 使用谷歌图表将mousedown事件注册为click
- 捕获元素jquery外部的mousedown事件
- 如何在JavaScript中测量交互和mousedown事件之间的延迟
- mousedown事件未在平板电脑/移动设备上启动,HTML5 Canvas
- $('option').mousedown 事件在少数情况下不起作用
- mousedown事件完成后销毁引导程序弹出窗口
- 是mousedown事件固有地比mouseup事件慢
- RaphaelJS中的mousedown事件不起作用
- iPhone文档mousedown事件未启动
- 如何使mousedown事件防止单击效果,并且只影响按住的单击
- 为什么在javascript中无法识别mousedown事件(带THREE)
- 如果单击了滚动条,则取消mousedown事件
- 如何检查mousedown事件是'javascript中滚动条上的t
- 如何在OpenLayers.Map上获取“mousedown”事件
- 高亮显示和取消高亮显示文本时,使用javascript管理mousedown事件
- jQuery:使用mousedown事件连续改变输入范围的值
- mouseDown事件处理程序downAction Override
- 在IE8中,jQuery mousedown事件不会触发窗口
- 取消锚元素
- 中包含的mousedown事件(使用纯js)
- 使用javascript的Mousedown事件