Javascript shiftKey事件属性不工作
我有两个提交按钮:“积极”和“消极”在我的html部分。我想发生的是,当用户按下SHIFT键,然后在身体上的任何位置执行鼠标向下移动时,在按下CTRL键并执行鼠标向下移动时,正按钮应被提交,负按钮应被提交。我的代码如下:Javascript shiftKey事件属性不工作,javascript,html,Javascript,Html,我有两个提交按钮:“积极”和“消极”在我的html部分。我想发生的是,当用户按下SHIFT键,然后在身体上的任何位置执行鼠标向下移动时,在按下CTRL键并执行鼠标向下移动时,正按钮应被提交,负按钮应被提交。我的代码如下: <head> <script> function check(event) { if (event.shiftKey==1) { var b1=documen
<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>
功能检查(事件)
{
if(event.shiftKey==1)
{
var b1=document.getElementById('btn1');
b1.提交();
}
if(event.ctrlKey==1)
{
var b1=document.getElementById('btn1');
b2.提交();
}
}
有人能告诉我哪里出了问题吗
<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>
document.addEventListener('click',函数(e){
if(e.shiftKey)document.getElementById('btn1')。单击();
如果(e.ctrlKey)document.getElementById('btn2')。单击();
},假);
在第二个
中,如果您有b2。分配b1
后提交()。这就是你的意思吗?