我想这是一个愚蠢的问题,但我无法解决这个问题。
当我打电话
audio.onloadeddata = function(){
alert('hello');
}
它不起作用,但是当我打电话时
audio.onloadeddata = alert('hello');
它确实有效。还在其他关于音频标签的网站上,它们使用与我相同的语法功能,那么为什么它对我不起作用?
我在这里有点绝望……
------------ 添加完整功能 -------------
jQuery('.btn-play-single').click(function(){
var statusTemp = jQuery('#statusTemp');
var button = jQuery(this);
var loader = jQuery('.ajax-loader',jQuery(this).parent());
var el = document.getElementById('record'+jQuery(this).attr('alt'));
if (el.paused){
statusTemp.append('<div>Sound is paused and i will play it</div>');
button.hide();
loader.show();
el.onloadeddata = function(){
statusTemp.append('<div>Sound has loaded and Im changing buttons</div>');
button.css({backgroundPosition:'0px -40px'});
loader.hide();
button.show();
el.play();
};
el.onended = function(){
statusTemp.append('<div>Sound has finished and changing buttons back</div>');
button.css({backgroundPosition:'0px 0px'});
};
} else {
button.css({backgroundPosition:'0px 0px'});
el.pause();
el.currentTime = 0;
statusTemp.append('<div>Sound was playing and I stopped it</div>');
}
});