1

我确定我正在做一些非常愚蠢的事情,但我无法让我的轮班事件触发。我都试过了:

$('.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 事件。

4

1 回答 1

1

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;
        }
    });
});
于 2010-08-26T09:50:13.093 回答