有没有办法阻止HTML的accesskey =“”从被激活? [英] is there a way to prevent HTML's accesskey="" from being activated?

查看:159
本文介绍了有没有办法阻止HTML的accesskey =“”从被激活?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试过 preventDefault(),但我没有成功。有没有我失踪的东西?

I tried preventDefault() but I haven't had success. Is there something that I'm missing?

如果可能,我会尝试全局禁用它(例如在窗口上注册事件

I would try to disable it globally, if possible (like registering the events on window)

推荐答案

似乎没有办法阻止事件触发。唯一的选择似乎是暂时删除accesskey属性,而不希望它们工作。这就是 jQuery UI必须用于模态对话框

There doesn't seem to be a way to stop the event from triggering. The only alternative seems to be to remove the accesskey attributes temporarily while you don't want them to work. That's what jQuery UI has to do for modal dialogs.

这是线程中的代码:

$("#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数据中,然后再将其删除:

As you can see it's saving the accesskey attributes to jQuery data before removing them:

$(this).data('ak', $(this).attr('accesskey')).removeAttr('accesskey')

然后从数据中恢复它们:

and then restoring them from the data:

$(this).attr('accesskey', $(this).data('ak'))

我对一个解决方案感兴趣,实际上可以防止事件而不是使用此解决方法。

I'd be interested in a solution that actually prevents the event rather than using this workaround.

这篇关于有没有办法阻止HTML的accesskey =“”从被激活?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆