HTML5下的Audio標籤控制項的歌曲播放暫停示範

來源:互聯網
上載者:User

標籤:style   blog   http   color   io   使用   java   ar   檔案   

 1 <!-- 使用了HTML5的標籤<audio> 圖片播放按鈕增加了監聽監聽事件,控制音樂的播放暫停 2      使用了document的幾個重要函數: 3      1.createElement建立標籤對象, 4      2.getElementById擷取對象以及img對象的src屬性 5      3.document.body添加控制項appendChild()函數 6      瞭解document的強大。可以建立對象,操作body標籤等--> 7 <!DOCTYPE html> 8 <html> 9 <meta http-equiv="Content-Type" content="text/html;charset=utf-8">10     <body>11         <h3>音樂播放暫停樣本</h3>12 13         <p>點擊按鈕,播放、暫停音樂</p>14 15         <img id="image_button" src="source/pause.jpg" onclick="myFunction()"></button>16 17         <p id="txt">點擊按鈕播放音樂</p>18 19         <script type="text/javascript">20             var isPlay = false;21             var x = document.createElement("AUDIO");22             x.setAttribute("src", "source/music.mp3");23             document.body.appendChild(x);24             function myFunction()25             {26                 if (isPlay == false) {27                     x.play();28                     document.getElementById("image_button").src="source/play.jpg";29                     document.getElementById("txt").innerHTML = "<浮誇> —— eason";30                     isPlay = true;31                 }else{32                     x.pause();33                     document.getElementById("image_button").src="source/pause.jpg";34                     document.getElementById("txt").innerHTML = "點擊按鈕播放音樂";35                     isPlay = false;36                 }37             }38         </script>39 40     </body>41 </html>

注意需要將pause.jpg,play.jpg,music.mp3放到source檔案夾下面。
檔案結構是{index.html,source[pause.jpg,play.jpg,music.mp3]}  (index.html就是上面貼的代碼檔案,儲存成html格式的。)

HTML5下的Audio標籤控制項的歌曲播放暫停示範

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.