如何将背景音乐添加到您的网页?
javascriptweb developmentfront end scripts
要在网页上添加背景音乐,请使用 <embed>…</embed> 元素。此外,使用 autoplay 属性。这将在页面加载时在后台运行音乐。
设置 width 和 height,使播放器隐藏在网页上。添加 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>