我知道已经有很多与此相关的问题,但是我尝试了其余的问题,但似乎没有用。
这是我的代码的一部分:
<?php
<a href='Recordings/Marvin Gaye Lyrics by Charlie Puth feat. Meghan Trainor.mp3'>Play the music</a>'
?>
在同一页面上将有很多这样的超链接,可以播放音乐,但这是在我被定向到录制链接之后。如何停止呢?
感谢您的提前帮助!
设法解决了..
注意事项:
1)我将@dagon的Javascript放入php的echo中。
2)我改用按钮,然后隐藏它的背景。
这是代码:
<audio id=\"player\">
<source src=\"Recordings/Marvin Gaye Lyrics by Charlie Puth feat. Meghan Trainor.mp3\" type=\"audio/mpeg\">
</audio>
<div>
<button class=\"link\" onclick=\"document.getElementById('player').play()\">Insert text here</button>
</div>
最佳答案
代替href,使用audio标签:
<audio controls>
<source src="Recordings/Marvin Gaye Lyrics by Charlie Puth feat. Meghan Trainor.mp3" type="audio/mpeg">
Your browser does not support the audio element.
</audio>
版本2,仅播放按钮:
<audio id="player">
<source src="Recordings/Marvin Gaye Lyrics by Charlie Puth feat. Meghan Trainor.mp3" type="audio/mpeg">
</audio>
<div>
<button onclick="document.getElementById('player').play()">Play</button>
</div>
关于php - 单击超链接但保留在同一页面上时播放声音,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34846158/