非常简单.我有一个用于触发函数的blur()事件处理程序,我想要在单击某个元素触发模糊时不触发该函数.
我尝试了document.activeElement,但我获得了一个HTMLBodyElement而不是我点击的元素.
码:
$j(".input_filtrare_camp").blur(
function(event) {
nr_img = this.parentNode.id.split("_")[1];
//alert(document.activeElement);
if(document.activeElement.id.indexOf("img_exact") < 0) //run only if the id of the element I clicked on doesn't contain "img_exact"
enter_input_filtrare(event.target);
});
Run Code Online (Sandbox Code Playgroud)
当然,警报用于故障排除.
我使用techfoobar的解决方案如下:
var currElem = null;
$(document).mousedown(function(e) {
currElem = e.target;
});
$j(".input_filtrare_camp").blur(
function(event) {
nr_img = this.parentNode.id.split("_")[1];
if(currElem.id.indexOf("img_exact") < 0) //run only if the id of the element I clicked on doesn't contain "img_exact"
enter_input_filtrare(event.target);
});
Run Code Online (Sandbox Code Playgroud)
查看PointedEars的答案,了解有关此问题的一些重要信息.