2013-06-01 109 views
1

我想通过调用jquery函数加载我的网站后播放ogg文件。我该如何做?加载网站后播放ogg声音

<script> 
    $(window).load(function(){ 

     // here i want to call this function to play my sound. 

    }); 
</script> 
+0

在这里看到:http://stackoverflow.com/questions/9419263/playing-audio-with-javascript – BIOS

回答

0

做这样

function play()   { 
    var audio=document.getElementById('audio1'); 
    audio.play(); 
        } 
      $(window).load(function(){ 
      play(); 
            }); 

在HTML

<audio id="audio1" style="display:none;"> 
<source src="Audio.mp3" type="audio/mpeg"> 
<source src="Audio.ogg" type="audio/ogg"> 
<embed height="50" width="100" src="Audio.mp3"> 
</audio>