js点击空白处触发事件

我们经常会出现点击空白处关闭弹出框或触发事件
<div class="aa" style="width: 200px;height: 200px;background-color: red;"></div>

js代码
$(document).mouseup(function(e) {
		var _con = $('.aa'); // 设置目标区域
		if (!_con.is(e.target) && _con.has(e.target).length === 0) {
			alert("4545");
		}
	});

当我们点击此div之外的地方时会触发事件,这里可以写业务和逻辑

猜你喜欢

转载自1197581932.iteye.com/blog/2390208