Shift+点击事件问题

发布于 2024-09-15 17:51:31 字数 970 浏览 6 评论 0原文

我确信我正在做一些非常愚蠢的事情,因此无法正常工作,但我无法让我的轮班事件触发。我已经尝试过:

$('.ShowCannedReport_UserFilterDropdown').each(function (index, element) {
        $(element).bind('click', function (event) {
        if (!event.shiftKey && !event.ctrlKey) {
        ShowCannedReport_UserFilter_Blur(this, event);
        }
        else {
        ShowCannedReport_UserFilterWithShiftHeld = this;
        }
 });

和:

$('.ShowCannedReport_UserFilterDropdown').each(function (index, element) {
        $(element).click(function (event) {
            if (!event.shiftKey && !event.ctrlKey) {
                ShowCannedReport_UserFilter_Blur(this, event);
            }
            else {
                ShowCannedReport_UserFilterWithShiftHeld = this;
            }
        });
    });

这两个都显示 event.shiftkey 为未定义。知道我做错了什么吗?

ShowCannedReport_UserFilterDropdown 是一个多选下拉列表,并且 click 事件在两个版本上都会触发,但 Shiftkey 事件从未注册。

I'm sure i'm doing something terribly stupid for this not to work, but I can't get my shift event to fire. I've tried both:

$('.ShowCannedReport_UserFilterDropdown').each(function (index, element) {
        $(element).bind('click', function (event) {
        if (!event.shiftKey && !event.ctrlKey) {
        ShowCannedReport_UserFilter_Blur(this, event);
        }
        else {
        ShowCannedReport_UserFilterWithShiftHeld = this;
        }
 });

and:

$('.ShowCannedReport_UserFilterDropdown').each(function (index, element) {
        $(element).click(function (event) {
            if (!event.shiftKey && !event.ctrlKey) {
                ShowCannedReport_UserFilter_Blur(this, event);
            }
            else {
                ShowCannedReport_UserFilterWithShiftHeld = this;
            }
        });
    });

Both of these show the event.shiftkey as undefined. Any idea as to what i'm doing wrong?

ShowCannedReport_UserFilterDropdown is a multiselect dropdown and the click event is firing on both versions, but the shiftkey event is never registered.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

娇柔作态 2024-09-22 17:51:36

您能确定您的初始选择器正在工作吗?即:

$('.ShowCannedReport_UserFilterDropdown').length; //is this >0 ?

文档就绪事件处理程序中的代码是否可用?

我已经设置了一个 jsFiddle 来模仿您想要实现的目标,并且一切正常:
http://jsfiddle.net/xT4ke/

另外,当 jQuery 这样做时,为什么要迭代每个项目对你来说,这应该足够了:

$('.ShowCannedReport_UserFilterDropdown').click(function (event) {
        if (!event.shiftKey && !event.ctrlKey) {
            ShowCannedReport_UserFilter_Blur(this, event);
        }
        else {
            ShowCannedReport_UserFilterWithShiftHeld = this;
        }
    });
});

Can you be sure that your initial selector is working? I.e:

$('.ShowCannedReport_UserFilterDropdown').length; //is this >0 ?

Is the code inside the document ready event handler?

I've set up a jsFiddle that mimics what you are trying to achive, and all works ok:
http://jsfiddle.net/xT4ke/

Also, why are you iterating through each item when jQuery does that for you, This should suffice:

$('.ShowCannedReport_UserFilterDropdown').click(function (event) {
        if (!event.shiftKey && !event.ctrlKey) {
            ShowCannedReport_UserFilter_Blur(this, event);
        }
        else {
            ShowCannedReport_UserFilterWithShiftHeld = this;
        }
    });
});
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文