相关疑难解决方法(0)

怎么能告诉我我点击了哪个元素来触发模糊事件处理程序?

非常简单.我有一个用于触发函数的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的答案,了解有关此问题的一些重要信息.

html javascript events

2
推荐指数
1
解决办法
4753
查看次数

标签 统计

events ×1

html ×1

javascript ×1