使用JavaScript生成的​​声音 [英] Generate sound using JavaScript

查看:298
本文介绍了使用JavaScript生成的​​声音的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想用JavaScript来生成声音。我用下面的code

I am trying to generate sound using JavaScript. I have used the following code

<html>
  <script type="text/javascript" src="jquery-1.4.2.js"></script>
  <script>
    function PlaySound(soundObj) {
      var sound = document.getElementById(soundObj);
      sound.Play();
    }

    function init() {
      //alert("");
      PlaySound('sound1')
    }

    window.onload = init;
  </script>

  <body>
    <form name="myform">
      <input type=button id="b1" name="b1name" value="Play Sound" onClick="PlaySound('sound1')">
    </form>
    <a href="#" onMouseOver="PlaySound('sound1')">Move mouse here</A>
    <embed src="beep-5.wav"  autostart="false" width="0" height="0" id="sound1" enablejavascript="true">
  </body>
</html>

正在按钮点击鼠标悬停产生的声音。它不是在正在生成的init 功能。如果我调用另一个JavaScript函数下面的函数,这是行不通的。还有一点就是,如果我保持通话前报警,然后发出声音。

Sound is being generated on button click and on mouseover. It is not being generated in the init function. If I call the below function in another JavaScript function, it does not work. Another point is that if I keep alerting before calling, then sound comes.

PlaySound('sound1')

我一直在使用 $(#B1)点击()尝试; (在JavaScript按一下按钮),但它不工作

I have tried using $("#b1").click(); (button click in JavaScript) but it's not working.

我知道这是重复的这个问题,但答案有我没有工作。我真的很困惑。请大家帮帮忙。

I know this is duplicate of this question, but the answer there did not work for me. I am really confused. Please help out.

我可以在同一时间玩这个声音两次?

Can I play this sound twice at a time?

推荐答案

如果我们在,的 http://plugins.jquery.com/project/sound_plugin 在启动/ Java脚本没有太多的延迟播放声音。在IE和Firefox正常工作。

If we generate sound using jquery sound plug in, http://plugins.jquery.com/project/sound_plugin playing sound on start up/java script without much delay. Working fine in IE and firefox.

这篇关于使用JavaScript生成的​​声音的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆