简体   繁体   English

shiftKey事件属性不起作用

[英]shiftKey Event Attribute not working

I have two submit buttons: 'positive' and 'negative' in my html part. 我的html部分有两个提交按钮:“正”和“负”。 What i want to happen is that when user presses SHIFT KEY and then does mousedown anywhere on the body the POSITIVE BUTTON should get submitted and the NEGATIVE BUTTON should get submitted on pressing CTRL KEY and doing mousedown. 我想发生的是,当用户按下SHIFT键,然后将鼠标放在身体上的任何位置时,应按CTRL键并进行mousedown时提交正按钮,而负按钮则应提交。 My code is as follows: 我的代码如下:

<head>
    <script>
        function check(event)
        {
        if (event.shiftKey==1)
        {
            var b1=document.getElementById('btn1');
            b1.submit();
        }

        if (event.ctrlKey==1)
        {
            var b1=document.getElementById('btn1');
            b2.submit();
        }

        }
 </script>
</head>
<body onmousedown="check(event)">
    <form method="post" action="fetch_page.php">
   <input type="submit" name="submit1" value="Positive" id="btn1" class="btn btn-primary"></input>
   <input type="submit" name="submit2" value="Negative" id="btn2" class="btn btn-primary"></input>
    </form>
</body>

Can someone tell me where am i going wrong?? 有人可以告诉我我要去哪里错吗?

<head></head>
<body>
    <form method="post" action="fetch_page.php">
        <input type="submit" name="submit1" value="Positive" id="btn1" class="btn btn-primary"></input>
        <input type="submit" name="submit2" value="Negative" id="btn2" class="btn btn-primary"></input>
    </form>
    <script>

        document.addEventListener('click', function(e) {
            if (e.shiftKey) document.getElementById('btn1').click();
            if (e.ctrlKey)  document.getElementById('btn2').click();
        }, false);
    </script>
</body>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM