播放声音文件onMouseOver事件

时间:2011-04-21 18:20:32

标签: javascript html xhtml

我希望我的声音文件在我的image.my代码无法正常工作时播放任何人可以提供帮助,如果有1个人这样做,请告诉我代码。提前知道

function Sound(surl) {
  document.getElementById("myspan").innerHTML=
    "<embed src='"+surl+"' hidden=true autostart=true loop=false>";
}


<span id=myspan></span>
<form>
<img src="imag.jpg" onMouseOver="Sound('success.wav')" />
</form>

2 个答案:

答案 0 :(得分:4)

<html>
<head>
<script type="text/javascript">
    function sound(surl) {
        document.getElementById("myspan").innerHTML =
        "<embed src="+surl+" hidden=true autostart=true loop=false>";
    }
</script>
</head>
<body>

<span id="myspan"></span>

<form>
    <img src="image.jpg" onmouseover="sound('success.wav')" />
</form>

</body>
</html>

这已经过测试并且正在运行。可能只想在CSS中鼠标悬停时更改光标。

答案 1 :(得分:1)

  

我测试的工作正常代码你   在逃脱角色中犯了一个错误   嵌入

<html>
<head>
<script language="javascript" type="text/javascript">

function Sound(surl) {
alert("working");<!-- this will ensure function is called successfully-->

document.getElementById("myspan").innerHTML=
"<embed src=\""+surl+"\" hidden=\"true\" autostart=\"true\" loop=\"false\" />";
}
</script>

</head>
<body>
<span id="myspan"></span>
<form>
<img src="imag.jpg" onMouseOver="Sound('success.wav')" />   
</form>
</span>
</body>
</html>