为什么我的JS音频按钮不能在Internet Explorer中工作?

时间:2018-01-24 11:47:10

标签: javascript html function internet-explorer onclick

我最近尝试制作一个基本网页,其中包含一个按钮,单击此按钮后,将开始播放本地文件中的音乐。它在Chrome中运行得非常好,但在Internet Explorer中无法正常工作。

将包含以下代码,但不确定我是否缺少某些基本行以使其兼容,或者是否存在更基础的问题。

<!DOCTYPE html>
<html>
<head>
    <title>Testing Audio Stream</title>
    <link href = "style.css" type = "text/css" rel = "stylesheet">
    <script src = "javascript.js"></script>
</head>
<body>
    <button id = "button" type = "button" onclick = 
    "testAudio('audio.mp3')">
    Test Audio
    </button>
</body>
</html>

单独的JS文件。

function testAudio(path) {
    var audio = document.createElement('audio');
    audio.setAttribute('src', path);
    audio.play();
}

0 个答案:

没有答案