有没有一种方法可以防止HTML&#39的accesskey =&“&"从被激活? [英] is there a way to prevent HTML's accesskey="" from being activated?

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

问题描述

我尝试了 preventDefault(),但是没有成功.有什么我想念的吗?

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

如果可能的话,我会尝试全局禁用它(例如在 window 上注册事件)

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

推荐答案

似乎没有一种方法可以阻止事件触发.唯一的替代方法似乎是在您不希望它们起作用的同时暂时删除accesskey属性.这就是 jQueryUI必须用于模式对话框.

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'))
        })
    }
});

如您所见,它在删除访问键属性之前将它们保存到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&#39的accesskey =&“&"从被激活?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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