我正在使用音频标签,我希望它可以计算播放了多少次。
我的代码是这样的:
<audio id="sound" controls="controls" onplaying="doing(this.id)">;
<source src="path/filename" type="audio/wav/">;
</audio>;
<input type="text" id="numbers" value= "0" >
然后在javascript文件中
Var n=0;
function doing(onplaying)
{
n = n+1;
document.getElementById("numbers").value = n;
}
但它不起作用,有人知道如何做到这一点,就像这样或以不同的方式。 提前谢谢。
答案 0 :(得分:1)
您可能想要play
个活动,而不是playing
:http://jsfiddle.net/a84rC/。
document.getElementById("sound").addEventListener('play', doing); // bind event
var n = 0;
function doing() {
n++; // increase (this is a shortcut to n = n + 1)
document.getElementById("numbers").value = n;
}