我想执行空格键(键码32)并多次运行setInterval。但现在我只能让空格键工作一次。
我想摆脱setInterval。当我再次按空格键时,setInterval应该会再次运行。
document.onkeydown = function onkeydown(event) {
if (event.keyCode == 65) {
if (PosPlayN >= 150) {
PosPlayN -= 5;
}
}
if (event.keyCode == 68) {
if (PosPlayN <= 200) {
PosPlayN += 5;
}
}
if (event.keyCode == 32) {
var jump = setInterval(jumplp, 5);
function jumplp() {
if (jumpcheck <= 30) {
PosPlayN -= 2;
}
if (jumpcheck >= 31 && jumpcheck <= 60) {
PosPlayN += 2;
}
if (jumpcheck >= 60) {
// ----- I want to exit setInterval here -----
}
jumpcheck+=1;
}
}
if (event.keyCode == 17) {
pGo = 0;
}
}发布于 2012-12-20 22:45:12
if(jumpcheck >=60){
clearInterval(jump);
}https://stackoverflow.com/questions/13974461
复制相似问题