HTML:
<span class="search">我是按钮1</span><span><a class="clickme" href="#">我是按钮2</a></span>
<div class="div_d" style="display: none;">我是1那个弹出层</div>
<div class="div_e" style="display: none;">我是那个222222的2弹出层</div>
JS:
/**
* 点击按钮显示层,点击其他地方隐藏层
* @param {str} btnName
* @param {str} divName
* @param
* @arrange (512.笔记) jb51.cc
*/
var tarClickTip = function(btnName,divName) {
$('.' + btnName).click(function(e) {
$('.' + divName).show();
});
$(document).on('click',function(e) {
var e = e ? e : window.event;
var tar = e.srcElement || e.target;
var tarClassName = $(tar).attr("class");
if (tarClassName != btnName && tarClassName != divName) {
$('.' + divName).hide();
}
});
};
$('.clickme').click(tarClickTip('clickme','div_e'));
tarClickTip('search','div_d');