jQuery实现声音播放

HTML内容:

<div class="play">Play</div>
<div class="pause">Stop</div>

jQuery内容:

<script>
    $(document).ready(function() {
        var audioElement = document.createElement('audio');
        audioElement.setAttribute('src', 'audio.mp3');
        audioElement.setAttribute('autoplay', 'autoplay'); //打开自动播放
        //audioElement.load()

        $.get();

        audioElement.addEventListener("load", function() {
            audioElement.play();
        }, true);

        $('.play').click(function() {
            audioElement.play();
        });

        $('.pause').click(function() {
            audioElement.pause();
        });
    });</script>

链接地址:http://stackoverflow.com/questions/8489710/play-an-audio-file-using-jquery-when-a-button-is-clicked

你可能感兴趣的:(jquery,sound)