的HTML
<div id="selectPeriodRangePanel">
<p>Test</p>
</div>
<button id="period_select_range_btn">Select Range</button>
JQUERY
$("#period_select_range_btn").off().on("click", function(){
$("#selectPeriodRangePanel").toggle();
});
当我单击按钮时,将打开selectPeriodRangePanel DIV
。DIV
当我在其外部单击时,我想隐藏它。
我怎样才能做到这一点 ?
试试这个
$(document).on("click", function(e){
if($(e.target).is("#period_select_range_btn")){
$("#selectPeriodRangePanel").show();
}else{
$("#selectPeriodRangePanel").hide();
}
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id="selectPeriodRangePanel" style="display:none">
<p>Test</p>
</div>
<button id="period_select_range_btn">Select Range</button>
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句