Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/422.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript测验答案,按键输入而非鼠标点击_Javascript_Html_Input_Keyboard - Fatal编程技术网

Javascript测验答案,按键输入而非鼠标点击

Javascript测验答案,按键输入而非鼠标点击,javascript,html,input,keyboard,Javascript,Html,Input,Keyboard,对于一个项目,我正在用HTML和Javascript做一个测验。问题是我必须用鼠标选择答案。我想通过链接到按键来选择这些Anwser。我使用的是makey makey,因为它需要交互。makey makey有一些关键输入,如W、S、D、F、G 如此简短的总结:将A、B或C链接到W、A或S(或其他键输入) 这样我就不用用鼠标了,只要一个简单的按键就行了 document.body.onkeyup = function(event){ var tKey = (event.which) ? e

对于一个项目,我正在用HTML和Javascript做一个测验。问题是我必须用鼠标选择答案。我想通过链接到按键来选择这些Anwser。我使用的是makey makey,因为它需要交互。makey makey有一些关键输入,如W、S、D、F、G

如此简短的总结:将A、B或C链接到W、A或S(或其他键输入)

这样我就不用用鼠标了,只要一个简单的按键就行了

document.body.onkeyup = function(event){
    var tKey = (event.which) ? event.which : event.keyCode;
    if (tKey === 87) console.log('w')
    if (tKey === 65) console.log('a')
    if (tKey === 83) console.log('s')
}

编辑:问题二

您可以使用与按下按键相同的方式进行操作

// Wat een click / button-press doet
function answer(classe){
    //..
    //..
    //At the end of the function..
    if(currentQuestion === 10) //10 = max amount of questions = end of quiz (fill in your number instead)
        switch(points){
            case 0: //We reached 0 points
                alert('Do U even quiz bro???') //Display the message in the way you want. alert() is a quick try for that.
                break;
            case 20: //We reached 20 points in the quiz
                alert('Boo! U are bad') //Display the message in the way you want. alert() is a quick try for that.
                break;
            case 80: //We reached 80 points in the quiz
                alert('Congrats! U scored max.') //Display the message in the way you want. alert() is a quick try for that.
                break;
        }
}
如果您希望以灵活的计数(低于或大于的点数)显示消息,另一种解决方案

//连按一下按钮都没有
功能应答(E类){
//..
//..
//在函数的末尾。。
if(currentQuestion==10)//10=最大问题量=测验结束(填写您的数字){
如果(积分>=80)//我们达到了79分以上
alert('Congreats!U scored max.')//以您想要的方式显示消息。alert()是一个快速的尝试。
如果(点数>=20)//我们得到了超过19个点数
alert('Boo!U are bad')//以您想要的方式显示消息。alert()是一种快速尝试。
否则如果(分数<20)//我们得到的分数少于20分
alert('Do you even quick bro???)//以您想要的方式显示消息。alert()是一个快速的尝试。
}
}

我现在只想添加(我猜)if/else语句。这是测验的分数。以80分为例:恭喜!你最多得20分:嘘!你很坏。这是我现在拥有的代码:

//侯德邦
var点=0;
//惠迪格酒店
var-currentQuestion=0;
//比基克利克-------------------------------------------------------------------
var answers=document.getElementsByTagName('input');
//Voeg een事件处理程序单击toe和elke输入(=knop)
对于(i=0;i

你的选择对你有好处

Punten:


document.body.onkeyup任何用JS编写的测试都很容易作弊!!多谢各位Lain@Pablo:在这个问题上还需要帮助吗?非常感谢你。帮了我很多忙!道具II无法投票给你(分数太低),只需将其标记为已接受,以便其他人看到问题已解决。不需要投票。
// Wat een click / button-press doet
function answer(classe){
    //..
    //..
    //At the end of the function..
    if(currentQuestion === 10) //10 = max amount of questions = end of quiz (fill in your number instead){
        if (points >= 80) //We reached more than 79 points
            alert('Congrats! U scored max.') //Display the message in the way you want. alert() is a quick try for that.
        else if (points >= 20) //We reached more than 19 points
            alert('Boo! U are bad') //Display the message in the way you want. alert() is a quick try for that.
        else if (points < 20) //We reached less than 20 points
            alert('Do U even quiz bro???') //Display the message in the way you want. alert() is a quick try for that.
    }
}