Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/83.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 通过onclick=playSound命令使用多个音频文件以实现跨浏览器支持_Javascript_Html_Html5 Audio - Fatal编程技术网

Javascript 通过onclick=playSound命令使用多个音频文件以实现跨浏览器支持

Javascript 通过onclick=playSound命令使用多个音频文件以实现跨浏览器支持,javascript,html,html5-audio,Javascript,Html,Html5 Audio,我目前正在这个链接上使用onclick=playsound代码(http://webdesign.about.com/od/sound/a/play_sound_oncl.htm)带有一些风格的单选按钮,允许切换几个单一的音频文件 唯一的问题是,我不知道如何使用这种方法获得跨浏览器支持 有没有办法做到这一点 <div class="tabs" id="play-bar">

我目前正在这个链接上使用onclick=playsound代码(http://webdesign.about.com/od/sound/a/play_sound_oncl.htm)带有一些风格的单选按钮,允许切换几个单一的音频文件

唯一的问题是,我不知道如何使用这种方法获得跨浏览器支持

有没有办法做到这一点

                                <div class="tabs" id="play-bar">
                                <div class="tab">
                                    <input type="radio" id="tab-1" name="tab-group-1" checked onclick="playSound('soundfile1.wav');">
                                    <label for="tab-1">1</label>
                                </div>
                                <div class="tab">
                                    <input type="radio" id="tab-2" name="tab-group-1" onclick="playSound('soundfile2.wav');">
                                    <label for="tab-2">2</label>
                                </div></div>

1.
2.

只需对跨浏览器代码使用jQuery即可

HTML

<div class="tabs" id="play-bar">
  <div class="tab">
    <input type="radio" id="tab-1" name="tab-group-1" checked>
    <label for="tab-1">1</label>
  </div>
  <div class="tab">
    <input type="radio" id="tab-2" name="tab-group-1">
    <label for="tab-2">2</label>
  </div>
</div>
$('input[name="tab-group-1"]').click(function(){
  var num = $(this).prop('id').split('-')[1];
  playSound('soundfile'+ num +'.wav');
});