How to add audio to a HTML image?(如何将音频添加到 HTML 图像?)
问题描述
我对这一切还很陌生,但我正在尝试将音频 mp3 声音添加到 HTML 图像中,单击时会播放该图像.我怎样才能做到这一点?
I'm still new to all this, but I'm trying to add audio mp3 sound to an HTML image, which is played when clicked on. How can I do this right?
我已经尝试了一些东西,比如 '' 标签,或者安装基于 java 的东西,比如 soundmanager2,但是它们似乎都不起作用.问题是,我不知道如何正确使用它们.
I've already tries a few things, like the '' tag, or installing java-based stuff, like soundmanager2, however none of them seems to work. The problem is, that I don't know how to use them properly.
我正在使用dreamweaver CS6,其中应该有一个选项行为"-->播放声音,但它不存在,所以我迷失了这一切.
I'm using dreamweaver CS6, in which there should be an option "behaviour"--> play sound, but it's not there, so I'm lost with all this.
推荐答案
你可以使用 Audio和视频 DOM 方法 play()
和 pause()
onclick 图像 工作演示
You can achieve that using Audio and Video DOM methods play()
and pause()
onclick of image working Demo
<audio id="audio_play">
<source src="http://www.w3schools.com/tags/horse.ogg" type="audio/ogg" />
<source src="http://www.w3schools.com/tags/horse.mp3" type="audio/mpeg" />
</audio>
<img src="http://bit.ly/1kX7D49" onClick="document.getElementById('audio_play').play(); return false;" />
<img src="http://bit.ly/1mq0tIt" onClick="document.getElementById('audio_play').pause(); return false;" />
这篇关于如何将音频添加到 HTML 图像?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何将音频添加到 HTML 图像?


基础教程推荐
- fetch 是否支持原生多文件上传? 2022-01-01
- 如何添加到目前为止的天数? 2022-01-01
- 即使用户允许,Gmail 也会隐藏外部电子邮件图片 2022-01-01
- Bokeh Div文本对齐 2022-01-01
- Fabric JS绘制具有活动形状的多边形 2022-01-01
- 检查 HTML5 拖放文件类型 2022-01-01
- 在 contenteditable 中精确拖放 2022-01-01
- 原生拖动事件后如何获取 mouseup 事件? 2022-01-01
- npm start 错误与 create-react-app 2022-01-01
- Bootstrap 模态出现在背景下 2022-01-01