我有一點問題,這段代碼在內部工作正常,但似乎在外部文件中removeTransition函數不見了。我錯過了什麼讓它工作?謝謝!函數在外部JavaScript文件中不起作用
function playSound(e) {
const audio = document.querySelector(`audio[data-key="${e.keyCode}"]`);
const key = document.querySelector(`div[data-key="${e.keyCode}"]`);
if(!audio) return;
audio.currentTime = 0;
audio.play();
key.classList.add('playing');
}
function removeTransition(e) {
if (e.propertyName !== 'transform') return;
this.classList.remove('playing');
}
const keys = Array.from(document.querySelectorAll(".key"));
keys.forEach(key => key.addEventListener('transitionend', removeTransition));
window.addEventListener("keydown", playSound);
你是如何'將'你的代碼附加到HTML? – Dellirium
你能添加完整的html頁面代碼嗎? –