admin管理员组文章数量:1291337
Given the following markup:
<audio controls onclick="alert('hi')">
<source src="/url/track.mp3" type="audio/mpeg">
</audio>
I get no response from the onclick event. Seems like all the onclick events are bound to the player controls.
My goal is to run a separate function when the user hits "play".
Given the following markup:
<audio controls onclick="alert('hi')">
<source src="/url/track.mp3" type="audio/mpeg">
</audio>
I get no response from the onclick event. Seems like all the onclick events are bound to the player controls.
My goal is to run a separate function when the user hits "play".
Share Improve this question asked Dec 13, 2015 at 23:40 raisa chudinovaraisa chudinova 331 silver badge4 bronze badges2 Answers
Reset to default 9The onplay
attribute is what you're looking for.
<audio onplay="myFunction()">...</audio>
Here's some article on w3schools about it
You can place an invisible div over the audio element:
<script>
function catchClick(){
alert("hi");
}
</script>
<div onclick="catchClick()" style="position:absolute;z-index:1;width:300px;height:30px;">
</div>
<audio controls>
<source src="/url/track.mp3" type="audio/mpeg">
</audio>
Then, in the catchClick function you can pass the mouse clicks to the audio element via this method How to simulate a mouse click using javascript
本文标签: javascriptonclick event on ltaudiogt elementStack Overflow
版权声明:本文标题:javascript - onclick event on <audio> element - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741528753a2383626.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论