Javascript 从addEventListener()调用函数
我有下一个代码,无法调用ShowMedalMessage()函数Javascript 从addEventListener()调用函数,javascript,function,audio,addeventlistener,Javascript,Function,Audio,Addeventlistener,我有下一个代码,无法调用ShowMedalMessage()函数 var-totalsounds=3; var currentsound=1; var audioElement=document.createElement('audio'); setAttribute('src','notify.wav'); setAttribute('autoplay','autoplay'); audioElement.addEventListener('ended',function(){ 如果(curr
var-totalsounds=3;
var currentsound=1;
var audioElement=document.createElement('audio');
setAttribute('src','notify.wav');
setAttribute('autoplay','autoplay');
audioElement.addEventListener('ended',function(){
如果(currentsound
如果对函数的调用在audioElement.addEventListener之前,它将正确调用,但如果行显示MedalMessage(1);在里面,它不工作:(
谢谢!这对我在chrome和firefox中都很有用 赫斯是活的
函数showMessage(){
文件。编写(“声音播放”);
}
var=3;
var currentsound=1;
var audioElement=document.createElement('audio');
audioElement.setAttribute('src','http://www.wav-sounds.com/cartoon/bugsbunny1.wav');
setAttribute('autoplay','autoplay');
audioElement.addEventListener('ended',function(){
如果(currentsound
您是否检查了chrome/firefox中的控制台日志中的错误?我看不出代码有任何错误。它可能在事件触发时未启动,是否记录了一些错误?我发现firefox中的音频播放不正常…无论是否使用ShowMedalMessage()…怪异:/Uncaught TypeError:无法调用未定义文件的方法“add”。php:132 ShowMedalMessage file.php:132(匿名函数)ShowMedalMessage是全局定义的吗?哪一行是132?在firefox中不起作用..我不知道为什么,我无法从其他函数访问ShowMedalMessage…奇怪。live示例对你有用吗?如果它在firefox中不起作用,请尝试更新浏览器。你的示例在firefox中起作用,但我的示例在firefox中不起作用,正如你所看到的,函数n在任何浏览器中都不会调用。您应该真正修复本地文件中的javascript错误,也许在这之后脚本就会工作。在general_scripts.js的'document.mn_search is undefined'第512行有一个脚本
var totalsounds = 3;
var currentsound = 1;
var audioElement = document.createElement('audio');
audioElement.setAttribute('src', 'notify.wav');
audioElement.setAttribute('autoplay', 'autoplay');
audioElement.addEventListener('ended', function() {
if (currentsound < totalsounds) {
this.currentTime = 0;
this.play();
currentsound = currentsound + 1;
}
ShowMedalMessage(1);
}, false);
function showMessage() {
document.write("Sound played");
}
var totalsounds = 3;
var currentsound = 1;
var audioElement = document.createElement('audio');
audioElement.setAttribute('src', 'http://www.wav-sounds.com/cartoon/bugsbunny1.wav');
audioElement.setAttribute('autoplay', 'autoplay');
audioElement.addEventListener('ended', function() {
if (currentsound < totalsounds) {
this.currentTime = 0;
this.play();
currentsound = currentsound + 1;
}
showMessage();
}, false);
document.body.appendChild(audioElement);