javascript - jQuery mousedown 事件不会在 IE8 中为窗口触发

标签 javascript jquery internet-explorer-8 jquery-events

我在使用 IE8 中的 jQuery 连接窗口的 mousedown 事件时遇到问题。我没有收到任何错误,但该事件似乎并未触发。它在 IE9 和我尝试过的所有其他浏览器中都有效。这是我的代码:

<html>
<head>
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js" type="text/javascript"></script>
    <script type="text/javascript">
        function test(e) {
            alert('test');
        }

        $(document).ready(function () {
            $(window).mousedown(test);
        });     
    </script>   
</head>
<body>   
</body>
</html>

最佳答案

使用文档代替窗口

$(document).ready(function() {
    $(document).mousedown(function() {
        alert('test');
    });
});

关于javascript - jQuery mousedown 事件不会在 IE8 中为窗口触发,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8413958/

相关文章:

javascript - Angular 资源/解决延迟导致未定义的错误

javascript - JQuery 将事件附加到实例中的方法

javascript - 如何选择当前元素的下一个元素

javascript - Highcharts - 忽略数据表中的总计行

jquery - 获取同名数组字段的所有值

javascript - Reactjs:在JavaScript中,默认不绑定(bind)类方法

jquery - CSS 3 - 缩放 CSS 过渡

javascript - IE8 中的意外量词

对象中的 Javascript 对象错误

html - 使用 CSS3 和 Html5 在 IE8 中定位中心