单击图像时播放声音文件

编程入门 行业动态 更新时间:2024-10-28 12:15:55
本文介绍了单击图像时播放声音文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我不是原生的 HTML 程序员,所以请不要跳过我这个简单的问题。

< img name =track1src我有一张图片,我正在使用以下代码进行显示:

=images / track1.pngwidth =180height =180border =0id =track1alt =/>

我想要在点击图片时播放声音文件。我可以使图像成为一个按钮,但是由于某种原因,这会让页面的布局变得糟糕。

我可以使用任何播放器,但唯一的是我不想展示侵入性球员。我只想让用户按下图像并听到音乐。如果他按下另一张图像,则当前音乐需要停止播放,并且必须播放不同的声音。

请帮忙!感谢! 首先,您必须使用 jQuery的。 例如,您可以在您的页面中创建一些< div> ;

< div id =wrap>& nbsp;< / div> p>

然后,在您的JavaScript中,当您想要播放文件时,只需添加

'('#wrap')。append('< embed id =embed_playersrc =audio.wavautostart =truehidden =true>< / embed>');

整个代码看起来像这样;

< script type =text / javascriptsrc =jquery-1.7.1.js>< / script> < script type =text / javascript> $(document).ready(function(){ $('#track1')。click(function(){ $('#wrap')。append('< embed id =embed_playersrc =audio.wavautostart =truehidden =true>< / embed>'); }); }); < / script> < img name =track1src =images / track1.pngwidth =180height =180border =0id =track1alt =/> < div id =wrap>& nbsp;< / div>

希望这有助于您。

I am not a native HTML programmer, so please don't jump all over me about this simple question.

I have an image that, I am displaying using the following code:

<img name="track1" src="images/track1.png" width="180" height="180" border="0" id="track1" alt="" />

I want a sound file to be played when that image is clicked. I can make the image a button, but that is messing up the layout of the page for some reason.

I am okay with using any player, but the only thing is that I do not want to display an intrusive player. I just want the user to press the image and hear the music. If he presses another image, the current music needs to stop playing, and a different sound must be played.

Please help! Thanks!

解决方案

First you have to use jQuery. You may create some <div> in your page having some id, for example;

<div id="wrap">&nbsp;</div>.

Then, in your JavaScript, when you want to play the file, just add

$('#wrap').append('<embed id="embed_player" src="audio.wav" autostart="true" hidden="true"></embed>');

the whole code looks something like;

<script type="text/javascript" src="jquery-1.7.1.js"></script> <script type="text/javascript"> $(document).ready( function() { $('#track1').click(function(){ $('#wrap').append('<embed id="embed_player" src="audio.wav" autostart="true" hidden="true"></embed>'); }); }); </script> <img name="track1" src="images/track1.png" width="180" height="180" border="0" id="track1" alt="" /> <div id="wrap">&nbsp;</div>

Hope this helps.

更多推荐

单击图像时播放声音文件

本文发布于:2023-07-11 09:37:12,感谢您对本站的认可!
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:单击   声音文件   图像

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!