Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/89.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 音频自动播放_Javascript_Jquery_Html - Fatal编程技术网

Javascript 音频自动播放

Javascript 音频自动播放,javascript,jquery,html,Javascript,Jquery,Html,所以我一分钟前还在这里,想找到一种方法来做这件事,它想出了这个 $(document).ready(function() { var audioElement = document.createElement('audio'); audioElement.setAttribute('src', 'mixtaperainbow.mp3'); audioElement.setAttribute('autoplay', 'autoplay'); //audioEleme

所以我一分钟前还在这里,想找到一种方法来做这件事,它想出了这个

$(document).ready(function() {
    var audioElement = document.createElement('audio');
    audioElement.setAttribute('src', 'mixtaperainbow.mp3');
    audioElement.setAttribute('autoplay', 'autoplay');
    //audioElement.load()

    $.get();

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

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

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

但我不能不自动播放声音。。。有人请帮忙你把属性设置为自动播放吗?可能注释掉这行audioElement.setAttribute('autoplay','autoplay')@地板我已经试过了,但是它根本不起作用。当你注释掉那一行时,你在控制台中有错误吗?@floor控制台中没有显示任何东西aaah,soo。。。我累了,只需删除:audioElement.setAttribute('autoplay','autoplay');:)