javascript - 为什么 mousedown 不能在 <html> 标签上工作?

标签 javascript jquery

mousedown 事件仅在我单击元素而不是 html 元素时才起作用。为什么以及我能做什么?

var curFocus;
$(document.body).delegate('*','mousedown', function(){
    if ((this != curFocus) && // don't bother if this was the previous active element                
        ($(curFocus).is('.field'))  // if it was a .field that was blurred
    ) {
        $('.' + $(curFocus).attr("id")).removeClass("visible"); // take action based on the blurred element
    }

    curFocus = this; // log the newly focussed element for the next event
});

最佳答案

<html>标签有点笼统,它包含不可见的元素,例如 <head> ,尝试使用<body>标签。

关于javascript - 为什么 mousedown 不能在 <html> 标签上工作?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4209729/

相关文章:

javascript - 如何在 vuejs 中使用另一个 prop 中的 prop 作为默认值

javascript - 如何在leaflet.js上绘制不同颜色的路径叠加?

javascript - 刷新 DIV 动态

javascript - jquery ajax到文件://not working in IE

jquery - MVC 将数据传入和传出 Bootstrap Modal

javascript - 通过自动添加人员来创建Linkedin机器人

javascript - 如何访问多维数组数据?

javascript - jQuery 脚本清除表单数据但应该保留一个输入

javascript - iPad 上的 jQuery 单击事件无法正常工作

javascript - 使用 shift 和鼠标单击选择多个元素 - jquery