Javascript 单击事件的jQuery键盘快捷键

Javascript 单击事件的jQuery键盘快捷键,javascript,jquery,keyboard-shortcuts,zooming,Javascript,Jquery,Keyboard Shortcuts,Zooming,我想在我的网站上有一个模拟CTRL++(放大)的按钮。所以我需要创建两个按键之类的东西。我有以下功能,可触发1个按键: <html> <head> <script type="text/javascript" src="http://code.jquery.com/jquery-1.4.4.min.js"></script> <title>Stackoverflow</title> </head>

我想在我的网站上有一个模拟CTRL++(放大)的按钮。所以我需要创建两个按键之类的东西。我有以下功能,可触发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>

栈溢出
功能模拟按键(字符){
触发器({type:'keypress',其中:character.charCodeAt(0)});
}
函数pressCtrlPlus(){
模拟按键(“=”);
}
$(函数(){
$('body')。按键(功能(e){
警报(例如,哪个);
});
});
有人知道如何通过单击按钮来创建CTRL++事件吗

根据这个话题 我创建了以下测试:

<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>

栈溢出
函数缩放(zlevel){
var_body=parent.parent.document.body;
if(jQuery.browser.msie){
_body.style.zoom=zlevel;
}
其他的
{
if(typeof _body.style.MozTransform==“string”)
_body.style.MozTransform=“scale”(+(zlevel)+)”;
else if(typeof _body.style.zoom==“string”)
_body.style.zoom=(zlevel*100)+“%”;
}
}
知识产权是一种权利,是一种精英的权利,是劳动和财富的暂时性权利。但是,在最低限度上,我们需要一个实验室来进行日常工作。两人或两人在一个无教区的房间里互相指责。除偶尔因疏忽而死亡外,不得因疏忽而导致动物死亡


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

为了保持缩放功能,您需要记住当前的缩放级别

<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) {
        zlevel = $('#zlevel').val() * zlevel;
        $('#zlevel').val(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(0.9);">
<input type="button" value="Ctrl+" ONCLICK="zoomin(1.15);">
<input type="button"  value="Ctrl++" ONCLICK="zoomin(1.3);">
<input type="hidden" value="1" id="zlevel">
</body>
</html>

栈溢出
函数缩放(zlevel){
zlevel=$('#zlevel').val()*zlevel;
$('#zlevel').val(zlevel);
var_body=parent.parent.document.body;
if(jQuery.browser.msie){
_body.style.zoom=zlevel;
}
其他的
{
if(typeof _body.style.MozTransform==“string”)
_body.style.MozTransform=“scale”(+(zlevel)+)”;
else if(typeof _body.style.zoom==“string”)
_body.style.zoom=(zlevel*100)+“%”;
}
}
知识产权是一种权利,是一种精英的权利,是劳动和财富的暂时性权利。但是,在最低限度上,我们需要一个实验室来进行日常工作。两人或两人在一个无教区的房间里互相指责。除偶尔因疏忽而死亡外,不得因疏忽而导致动物死亡


的可能重复:和的可能重复。请在发布前搜索。很遗憾,上述所有解决方案都无法解决我的问题。我需要模拟CTRL+。这是因为当您使用div的zoomlevels等放大页面时,页面会从窗口中掉出来,使用CTRL进行i.o.o缩放+