home.handlebars
<script>
function setAudio(media_src){
console.log('media src: ' + media_src);
var player = document.getElementById('player');
player.src = media_src;
player.load();
player.play();
return false;
}
</script>
<audio id='player' controls autoplay>
</audio>
<a href="#" id = "link" onClick= "return setAudio({{this.id}});">Music</a>
我已确认“this.id”包含有效的网址。单击href后,唯一发生的事情就是将“#”附加到地址栏。音频标签不播放任何内容。
答案 0 :(得分:0)
啊我明白了。事实证明,我需要将参数传递给setAudio()
:
<a href="#" id = "link" onClick= "return setAudio('{{this.id}}');">Music</a>