如何在你的網頁中新增背景音樂?


若要給網頁新增背景音樂,使用 <embed>…</embed> 元素。同時,使用自動播放屬性。這會在網頁載入時在後臺播放音樂。

設定 widthheight 以使播放器隱藏在網頁上。loop 屬性用來指定音訊是否會重新開始。將音樂檔案新增到伺服器,並在 src 屬性中提及連結。

示例

你可以嘗試執行以下程式碼,給網頁新增背景音樂

實際演示

<!DOCTYPE html>
<html>
   <head>
      <title>HTML background music</title>
   </head>
   <body>
      <p>The music is running in the background.</p>
      <p>(Song: Kalimba which is provided as a Sample Music in Windows)</p>
      <embed src="/html/Kalimba.mp3" loop="true" autostart="true" width="2" height="0">
   </body>
</html>

更新於: 13-Sep-2023

34K+ 瀏覽

開啟您的 職業生涯

完成課程即可獲得認證

開始學習
廣告
© . All rights reserved.