html5中為audio標簽增加停止按鈕動作實現(xiàn)方法

字號:


    在html 5中的audio標簽中,只有暫停按鈕,但沒有停止按鈕,其實為其增加也不麻煩,方法如下:
    代碼如下:
    HTMLAudioElement.prototype.stop = function()
    {
    this.pause();
    this.currentTime = 0.0;
    }
    其實很簡單,就是先暫停,然后時間歸0;
    調用方法:
    代碼如下:
    var aud = new Audio();
    aud.src = '特殊他.ogg';
    aud.play();
    aud.stop();
    上面代碼可以在chrome,opera下跑,但firefox 17不行