效果图
代码如下
<div class="tan">
<div id="audio"></div>
<div class="play_b">
<div class="y1" >
<button type="button" onclick="play(1)" id="y1">1</button>
</div>
<div class="y2" >
<button type="button" onclick="play(2)" id="y2">2</button>
</div>
<div class="y3" >
<button type="button" onclick="play(3)" id="y3">3</button>
</div>
<div class="y4" >
<button type="button" onclick="play(4)" id="y4">4</button>
</div>
<div class="y5" >
<button type="button" onclick="play(5)" id="y5">5</button>
</div>
<div class="y6" >
<button type="button" onclick="play(6)" id="y6">6</button>
</div>
<div class="y7" >
<button type="button" onclick="play(7)" id="y7">7</button>
</div>
</div>
</div>
<script>
function play(str){
document.getElementById("audio").innerHTML='<audio autoplay="autoplay"><source type="audio/mp3" src="fonts/'+str+'.wav"></source></audio>';
}
</script>
标签:function,play,标签,innerHTML,getElementById,str,audio,mui From: https://blog.51cto.com/u_15955908/6039830