js点击空白关闭div

xiaoxiao2021-02-28  37

点击空白关闭div

1.html

<div class="tardiv">div块</div>

2.css

div { width: 200px; height: 200px; background: #eee; }

3.js

$(document).click(function(e) { var _con = $('.tardiv'); // 设置目标区域 if(!_con.is(e.target) && _con.has(e.target).length === 0) { $('.tardiv').remove(); } });
转载请注明原文地址: https://www.6miu.com/read-2624067.html

最新回复(0)