1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
<script> function playvoice(fileName) { if(document.getElementById('sound')){ document.body.removeChild(document.getElementById('sound')); } var sound=document.createElement("audio"); sound.controls="controls"; sound.id="sound"; sound.autoplay='autoplay'; sound.style.display='none'; document.body.appendChild(sound); var source = document.createElement('source'); source.src = fileName+'.ogg'; source.type='audio/ogg'; sound.appendChild(source); var sound2 = document.createElement('embed'); sound2.src = fileName+'.mp3'; sound2.autostart='true'; sound.appendChild(sound2); } </script> |
调用代码 <a onmouseover="playvoice('ding')" href="#">鼠标划过播放声音</a>
注意的是:一个音频文件要准备两种格式.ding.mp3;ding.ogg;
iis下默认MIME 没有audio/ogg类型,所以要自己添加,否则访问ogg文件会出现404
添加方法:
打开IIS管理器,打开“本地计算机”的属性——》MIME类型——》新建
后缀名:.ogg
MIME类型:audio/ogg
应用即可