通过按钮触发 Ctrl S 或 Ctrl P

发布于 2024-11-26 08:22:25 字数 207 浏览 1 评论 0原文

好吧,现在我知道你可以听按键(按键、按键等),但我想触发按键。就像用户按 CTRL+S 进行保存一样。

简单的问题是,是否可以使用 Jquery 同时触发 2 个按键?我一直在尝试查找此内容,但我发现的所有内容都在谈论捕获按键操作,而不是触发它们,特别是同时按下两个按键。

有什么想法可以实现这一点吗?如果您能引导我走上正确的道路,我将不胜感激。

Ok now I am aware that you can listen to keypresses (keydowns keyups etc...) but I would like to TRIGGER a keypress. Like as if the user presses CTRL+S to save.

Short question is, is it possible to use Jquery to trigger 2 key presses at the same time? I have been trying to look this up but all the stuff I found was talking about capturing key presses and not triggering them especially 2 key presses at the same time.

Any ideas how this can be accomplished? If you could lead me to the right track it would be much appreciated.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

苏别ゝ 2024-12-03 08:22:26

如果您想触发自己的处理程序代码,您应该将该代码放在一个单独的函数中并正常调用该函数。

如果你想触发浏览器的默认功能,你应该放弃;出于安全原因这是不可能的。 (尽管您可能对 window.print() 感兴趣)

If you want to trigger your own handler code, you should just put that code in a separate function and call the function normally.

If you want to trigger the browser's default functionality, you should give up; that is impossible for security reasons. (Although you may be interested in window.print())

蝶舞 2024-12-03 08:22:26

我不知道您是否可以触发按键,但也许如果您解释一下您具体想要实现的目标,您也许能够找到解决方案?

例如,如果您想触发 ctrl-p 来调出打印对话框,您可以使用 window.print();

如果您想在您的自己的代码,那么您可以直接调用代码而不是触发按键。

我认为没有任何方法可以触发文件 |不过,使用 JavaScript 另存为 (ctrl-s)。

I don't know if you can trigger the key presses but perhaps if you explain what you are specifically trying to achieve you might be able to find a solution?

For example, if you want to trigger ctrl-p to bring up the print dialog you can do this using window.print();

If you want to trigger actions in your own code then you can just call the code directly rather than triggering the key press.

I don't think there is any way to trigger a file | save as (ctrl-s) by using JavaScript though.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文