注册 登录
编程论坛 JavaScript论坛

极度简单的代码,就是不能运行,求大神阅一下!

freebirdbo 发布于 2016-02-26 22:42, 2472 次点击
<html>
<head>
<title>Audio</title>
<script>
function playSound(src){
var _s = document.getElementById('snd');
if(src!='' && typeof src!=undefined){
_s.src = src;
}
}
</script>
</head>
<body>
<input id="snd" type="button" value="play" onclick="playSound('http://mp3.')">
</body>
</html>
2 回复
#2
qq10235692232016-02-26 23:43
程序代码:
<!DOCTYPE html>
<html>
<head>
<title>Audio</title>
<meta charset="utf-8">
<script>
function playSound(s)  //由于javascript对变量特别敏感,_s.src = src;看起来不妥。
{
    var _s = document.getElementById('txt');
    if(s!='' && typeof(s)!='undefined')  //typeof(s)
    {
        _s.innerHTML = s;  //替换p中的文字
    }
}
</script>
</head>
<body>
<input id="snd" type="button" value="play" onclick="playSound('http://mp3.')">
<p id="txt">111111</p>
</body>
</html>
#3
冰镇柠檬汁儿2016-03-01 14:47
<!DOCTYPE html>

<html>
<head>
    <title>Audio</title>
    <script>
        function playSound(src) {
            var s = document.getElementById('snd');
            if (src != '' && typeof src != undefined) {
                s.src = src;
            }
            s.play();
        }
    </script>
</head>
<body>
    <video id="snd"></video>
    <input type="button" value="play" onclick="playSound('Hero.mp3')">
</body>
</html>

请注意以下几点:
1、播放MP3需要video标签
2、播放MP3需要调用video标签的play方法
1