JS Implementation page Click Button Play sound

Source: Internet
Author: User

jquery code (IE compatible, Firefox plug-in, Google Chrome compatible, opera did not respond)

The code is as follows Copy Code

$ (function () {
$ (' A.button '). Click (function () {
$ (' embed '). Remove ();
$ (' body '). Append (' <embed src= "Button.wav" autostart= "true" hidden= "true" loop= "false" > ");

Method Two

  code is as follows copy code

<div id= "Div1" ></div>
<input type= "button" value= "immediately" onclick= "Play_click" (This, ' http://www.xxx. Cc/1.wav '); "
<div id= "Div2" ></div>
<script language= "javascript"
function Play_click (sef,url) {
var div = document.getElementById (' Div1 ');
div.innerhtml = ' <embed src= ' +url+ ' loop= ' 0 ' autostart= ' true ' hidden= ' true ' ></embed> ';
var emb = document.getelementsbytagname (' EMBED ') [0];
if (EMB) {
/* can be written here to determine whether the WAV file has been loaded, the following is modeled with a settimeout */
div = document.getElementById (' div2 ');
Div.i nnerhtml = ' loading: ' +emb.src;
Sef.disabled = true;
settimeout (function () {div.innerhtml= ';},1000);


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.