javascript - 如何获取函数调用的元素的事件?
问题描述
我正在尝试通过函数获取元素的事件,有没有机会做到这一点?基本上我只想拥有包含-“randomChosenColour”ID的元素的事件-
var gamePattern = []
var buttonCoulors = ["red", "blue", "green", "yellow", "wrong"]
$(document).on("keypress", nextSequence)
function nextSequence() {
var randomNumber = Math.floor(Math.random() * 5)
var randomChosenColour = buttonCoulors[randomNumber]
var randomSound = "sounds/" + randomChosenColour + ".mp3"
var Sound = new Audio(randomSound)
gamePattern.push(randomChosenColour)
if (randomNumber < 5) {
$("#" + randomChosenColour).addClass("pressed")
setTimeout(function() {
$("#" + randomChosenColour).removeClass("pressed")
}, 100)
} else {}
Sound.play()
}
解决方案
推荐阅读
- java - Spring Boot 启动构建 JPA 容器非常慢
- python - 在 python 中使用正则表达式将文本文件拆分为单词
- javascript - 从纯 Javascript/JQuery 调用 Angular js 函数
- php - 我们如何更改依赖 composer.lock 文件的版本要求?
- python - 如何修复此“TypeError:float() 参数必须是字符串或数字,而不是‘方法’”错误?
- hibernate - 使用 SpringBoot Hibernate 和 Maven 的 Oracle 数据库连接错误
- c# - 将投影点映射到真实世界的点
- c# - 从 32 位应用程序获取 64 位应用程序的进程信息
- django - Python 3 TypeError:需要字符串参数,得到 'bytes' casperjs_capture
- postgresql - 将列上的纪元时间保存到另一列 postgres