在 HTML 中,每次视频/音频音量改变时执行脚本?
htmlweb developmentfront end technology更新于 2025/8/15 22:36:17
当用户改变网页上访问的视频或音频的音量时,会触发 onvolumechange 属性。此改变可以是调高、调低、静音等。
示例
您可以尝试运行以下代码来实现 onvolumechange 属性 −
<!DOCTYPE html>
<html>
<body>
<h2 id="test">Play</h2>
<video id = "myid" width = "320" height = "176" controls onvolumechange = "myFunction()">
<source src = "/html5/foo.ogg" type = "video/ogg" />
<source src = "/html5/foo.mp4" type = "video/mp4" />
Your browser does not support the video element.
</video>
<script>
function myFunction() {
document.getElementById("test").innerHTML = "Volume changed";
}
</script>
</body>
</html>
相关文章
有用资源
html 参考教程 - 该教程包含有关 html 的更多信息:https://www.cainiaomax.com/html/

