This article describes how js controls the playback and stop of web background music. Share it for your reference. The specific implementation method is as follows:
Copy the code as follows:<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>JS method to control background music bgsound (start and stop)</title>
</head>
<body>
<script type="text/javascript">
var bg_sound=document.createElement_x("bgsound");//Create background music
bg_sound.id="i_bg"//Set the id attribute
document.body.appendChild(bg_sound);//Add background music in body
//bg_sound.src="tmp3.mp3";
i_bg.src="tmp3.mp3";//Set a background music file
//It should also be written in write, you can try the effect.
function bg_stop(){
i_bg.src="";
}
function bg_start(){
i_bg.src="tmp3.mp3";
}
</script>
<span ><a onclick="javascript:bg_stop();" href="javascript:void(0);">Background music stop</a></span> <span ><a onclick="javascript:bg_start();" href="javascript:void(0);">Background music start</a></span>
</body>
</html>
I hope this article will be helpful to everyone's JavaScript programming.