似乎没有办法阻止事件触发。唯一的选择似乎是在您不希望它们工作时暂时删除 accesskey 属性。就是这样jQuery UI 必须处理模式对话框 https://forum.jquery.com/topic/jquery-ui-modal-dialog-not-blocking-accesskey-of-buttons-on-parent-window.
这是该线程的代码:
$("#boxA-dialog").dialog({
autoOpen: false,
modal: true,
height: 400,
width: 300,
open: function(event, ui) {
ak = $('[accesskey]').each(function() {
$(this).data('ak', $(this).attr('accesskey')).removeAttr('accesskey')
})
},
close: function(event, ui) {
ak.each(function() {
$(this).attr('accesskey', $(this).data('ak'))
})
}
});
正如您所看到的,它在删除 accesskey 属性之前将其保存到 jQuery 数据中:
$(this).data('ak', $(this).attr('accesskey')).removeAttr('accesskey')
然后从数据中恢复它们:
$(this).attr('accesskey', $(this).data('ak'))
我对实际阻止该事件的解决方案感兴趣,而不是使用此解决方法。