jQuery判断当前点击位置是否非指定元素区域
$(document).click(function(e){
var spanDatebox = $('#date').next('.datebox');
var idValue = $(e.target).attr("id"); //获取当前点击区域对象的id值
if(idValue == "dateLabel"){
spanDatebox.addClass("focus");
}else if(idValue == undefined || idValue != "dateLabel"){ //不在该dateLabel点击区域内
spanDatebox.removeClass("focus");
}
})
重点内容
代码解读:当点击区域的id是dateLabel进行加载焦点样式,反之移除该样式。
e.target可以获取到当前点击的element对象
注:本文全部为平时网上工作学习时搜索到的参考资料,内容太多所以就不一一加上原文链接了。