How js adds background music to webpages and selects sound effects

Source: Internet
Author: User

How js adds background music to webpages and selects sound effects

This article mainly introduces how to add background music and select sound effects to the webpage by js. It involves the javascript audio operation technique and has some reference value. If you need it, you can refer to it.

 

 

This article describes how to add background music and select sound effects to a webpage by js. Share it with you for your reference. The specific implementation method is as follows:

 

The Code is as follows:

<HTML>
<HEAD>
<TITLE> Add background music to the webpage and select the sound effect function </TITLE>
<STYLE>
<! -- Style sheet -->
A {font-size: 30pt; color: blue; font-family: Vineta BT}
A: link {text-decoration: none ;}
A: hover {text-decoration: none; color: red}
A: visited {text-decoration: none ;}
. 20pt {font-size: 20pt; color: # ff66cc}
</STYLE>
<Script language = javascript>
Var mid = new Array ()
Mid [1] = "sound/201101/S01.wav"
Mid [2] = "sound/201101/S02.wav"
Function clicksound (I)
{
Document. all. sound. src = mid [I]
}
</Script>
</HEAD>
<BODY>
<Bgsound id = sound src = "" loop = 1>
<Bgsound src = "sound/201101/Abuse. mid">
<Center>
<A href = "#" onclick = "clicksound (1)"> NO! NO! NO! </A> <br>
<A href = "#" onclick = "clicksound (2)"> You Win! Cheers! </A> <br>
<Hr width = 700>
<Font class = 20pt> when you click the content above, a dynamic background sound is displayed. </font>
</Center>
</BODY>
</HTML>

 

I hope this article will help you design javascript programs.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.