gpt4 book ai didi

jquery - 禁用浏览器的 'ctrl+s'默认功能

转载 作者:行者123 更新时间:2023-12-03 22:26:38 24 4
gpt4 key购买 nike

我使用jQuery-hotkeys

以及以下代码:

$(document).bind('keydown', 'ctrl+s', function(){$('#save').click()});

但我无法禁用浏览器的默认行为。如何禁用它?

最佳答案

看起来您从处理程序返回 false 以禁用“冒泡”事件。所以:

$(document).bind('keydown', 'ctrl+s', function(){$('#save').click(); return false;});

...但它可能是特定于浏览器的。来自 your link :

Firefox is the most liberal one in the manner of letting you capture all short-cuts even those that are built-in in the browser such as Ctrl-t for new tab, or Ctrl-a for selecting all text. You can always bubble them up to the browser by returning true in your handler.

Others, (IE) either let you handle built-in short-cuts, but will add their functionality after your code has executed. Or (Opera/Safari) will not pass those events to the DOM at all.

So, if you bind Ctrl-Q or Alt-F4 and your Safari/Opera window is closed don't be surprised.

关于jquery - 禁用浏览器的 'ctrl+s'默认功能,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3571509/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com