音乐代码是什么意思?
音乐代码是什么意思?
音乐代码是指包含音乐地址的代码,用于在网页中播放背景音乐。
在使用音乐代码时,请注意以下几点:
输入的音乐地址必须是网络地址,而不是电脑本地路径地址,这样才能确保音乐能够在网页浏览器中正常播放。
我们来看看最常用的两种音乐代码:
第一种代码:
```html <embed autostart="true" loop="-1" controls="ControlPanel" width="" height="" src="你的背景音乐地址">
这种代码的特点是:即使窗口最小化,音乐仍然会继续播放,直到网页窗口关闭,这种代码的播放效果更为持久,但兼容性较低,可能会影响部分浏览器的性能。
两种代码的共同点是:当当前窗口被关闭或按下ESC键时,音乐都会停止播放。
两种代码都需要放在网页的<head>标签之间。
如果你希望网页打开时自动播放背景音乐,可以在<body>区域内添加以下代码:
```html <SCRIPT language="JavaScript">
<!--
var sound1="song1.mid"
var sound2="song2.mid"
var sound3="song3.mid"
var sound4="song4.mid"
var sound5="song5.mid"
var sound6="song6.mid"
var sound7="song7.mid"
var sound8="song8.mid"
var sound9="song9.mid"
var sound10="song10.mid"
var x=Math.round(Math.random()*9)
if (x==) x=sound1
else if (x==1) x=sound2
else if (x==2) x=sound3
else if (x==3) x=sound4
else if (x==4) x=sound5
else if (x==5) x=sound6
else if (x==6) x=sound7
else if (x==7) x=sound8
else if (x==8 ) x=sound9
else x=sound10
if (navigator.appName=="Microsoft Internet Explorer" )
document.write('<bgsound src='+'+x+'+' loop="infinite">')
else
document.write('<embed src='+'+x+'+' hidden="true" border="" width="20" height="20" autostart="true" loop="true">')
</SCRIPT>