gpt4 book ai didi

javascript - 通过 clickevent 实现 jQuery 键盘快捷键

转载 作者:行者123 更新时间:2023-11-28 10:24:11 26 4
gpt4 key购买 nike

我希望在我的网站上有一个模拟 CTRL + +(放大)的按钮。所以我需要创建 2 个按键或其他东西。我有以下触发 1 个按键的命令:

<html>
<head>
<script type="text/javascript" src="http://code.jquery.com/jquery-1.4.4.min.js"></script>
<title>Stackoverflow</title>
</head>
<body>
<script type="text/javascript">
function simulateKeyPress(character) {
jQuery.event.trigger({ type: 'keypress', which: character.charCodeAt(0) });
}

function pressCtrlPlus() {
simulateKeyPress("=");
}

$(function () {
$('body').keypress(function (e) {
alert(e.which);
});
});
</script>

<input type="button" value="Ctrl +" ONCLICK="pressCtrlPlus();">

</body>
</html>

有人知道如何通过单击按钮来创建 CTRL + + 事件吗?

最佳答案

根据本主题SO: Calling keyevent from mouse我创建了以下测试:

<html>
<head>
<script type="text/javascript" src="http://code.jquery.com/jquery-1.4.4.min.js"></script>
<title>Stackoverflow</title>
</head>
<body>
<script type="text/javascript">
function zoomin(zlevel) {
var _body = parent.parent.document.body;

if (jQuery.browser.msie) {
_body.style.zoom = zlevel;
}
else
{
if (typeof _body.style.MozTransform == "string")
_body.style.MozTransform = "scale(" + (zlevel) + ")";
else if (typeof _body.style.zoom == "string")
_body.style.zoom = (zlevel*100) + "%";
}
}
</script>

<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>

<input type="button" value="Ctrl0" ONCLICK="zoomin(1.0);">
<input type="button" value="Ctrl+" ONCLICK="zoomin(1.15);">
<input type="button" value="Ctrl++" ONCLICK="zoomin(1.3);">
</body>
</html>

但它仍然表现得很奇怪。我还没有看到任何解决方案,其作用类似于使用键盘快捷键 CTRL + + 进行缩放。这还做不到吗?

关于javascript - 通过 clickevent 实现 jQuery 键盘快捷键,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4838245/

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