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

查看:151
本文介绍了如何将音频添加到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,在其中应该有一个选项"behaviour"(行为)->播放声音,但是它不存在,所以我迷失了所有这些.

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.

推荐答案

您可以使用音频来实现和视频DOM方法 play()pause()单击图像工作演示

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天全站免登陆