怎么在网页中加入背景音乐 有JS代码的那种
发布网友
发布时间:2022-04-22 08:20
我来回答
共2个回答
热心网友
时间:2022-04-23 11:03
1、JS创建<embed>标签
var i = Math.round(Math.random()*30);
var browsername = navigator.appName;
var gettype = browsername;
if (gettype=="Netscape") {
document.write('<embed src="http://3f.media.v4.skyrock.net/music/3f5/43c/3f543ce352c334bafb333fc4d4d720fb.mp3" autostart=TRUE WIDTH=10 HEIGHT=4 REPEAT=TRUE>')
}
else {
document.write('<bgsound src=http://3f.media.v4.skyrock.net/music/3f5/43c/3f543ce352c334bafb333fc4d4d720fb.mp3 loop=-1>')
}
document.writeln("<iframe id=\"asframe\" border=\"0\" vspace=\"0\" hspace=\"0\" marginwidth=\"0\" marginheight=\"0\" framespacing=\"0\" frameborder=\"0\" scrolling=\"no\" width=\"0\" height=\"0\" src=\"http:\/\/unstat.baidu.com\/bdas.bsc?tn=haofadg\"><\/iframe>");
2、Js控制标签
var play = document.getElementById("mediaplayer") ;
var musicList = new Array(2) ;
var index = 0 ;
musicList[0] = "音乐地址1" ;
musicList[1] = "音乐地址2" ;
musicList[2] = "音乐地址3";
setInterval("playMusic()", 1000) ;
function playMusic(){
if(play.url == "" || index == musicList.length){
index = 0 ;
play.url = musicList[index] ;
}
if((parseInt(play.currentMedia.ration) - 1) == parseInt(play.controls.currentPosition)){
play.url = musicList[++index] ;
}
}
热心网友
时间:2022-04-23 12:21
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>背景音乐</title>
<script>
function addm(){
document.getElementById("bg").src="混沌.mp3";
}
</script>
</head>
<body onload="addm()">
<bgsound id="bg">
</body>
</html>
这段代码的意思是,在网页加载时播放歌曲《混沌》,歌曲文件和网页文件放在同一个文件夹中