0

我目前正在创建一个网站。

我有很多网站/资源,可以去做我想做的事。但是他们的方式/步骤对我不起作用。

我有以下情况:

我在 Dreamweaver 中有 2 个 cols。1 用于图像,正确的 col 用于文本。

我希望用户单击图像并听到图片中人的音频。没有播放器或其他页面打开。单击图像并听到音频就是它。

这可以做到吗。由于当前唯一的例子似乎让我不确定:

http://www.it-student.org.uk/playsound/playsounds.php

我设置它,因为它要求什么都没有发生没有声音。

<title>Untitled Document</title> 
<script> 
  function EvalSound(soundobj) { 
    var thissound= eval("document."+soundobj); 
    thissound.Play();
  } 
</script>
</head>
<body>
  <embed src="hannbil smith.mp3" autostart=false width=0 height=0 name="sound1" enablejavascript="true">
   <a href="#" onClick="EvalSound('sound1')"><img src="han cast.jpg""></a> 
</body> 
</html>
4

2 回答 2

0

您至少需要关闭嵌入标签并从 URL 中删除空格。EVAL 也是 EVIL。最后从 onclick 返回 false

我给了它一个 ID 并使用 getElementById

<!DOCTYPE html>
<html>
<head>
<title>Untitled Document</title> 
<script> 
  function evalSound(soundobj) { 
    var thissound=document.getElementById(soundobj); 
    thissound.Play();
    return false;
  } 
</script>
</head>
<body>
  <embed src="hannbil%20smith.mp3" autostart=false width=0 height=0 name="sound1" id="sound1" enablejavascript="true" />
   <a href="#" onclick="return evalSound('sound1')"><img src="han%20cast.jpg""></a> 
</body> 
</html>
于 2013-08-25T16:23:13.263 回答
0

这可以使用 jQuery 轻松完成

演示jsFiddle

var manifest = [
    {id:"waiting", src:"http://stardotserver.co.uk/waiting2.ogg"}  
]
var preload = new createjs.LoadQueue()
preload.installPlugin(createjs.Sound)
preload.loadManifest(manifest)

$('img').on('click',function() {
    createjs.Sound.play("waiting", createjs.Sound.INTERRUPT_NONE, 0, 0, -1, .5)
});
于 2013-08-25T16:01:14.403 回答