如何将音频添加到 HTML 图像? [英] How to add audio to a HTML image?

查看:84
本文介绍了如何将音频添加到 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 图像?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆