开发者

playing sound file onMouseOver event

i want my sound file to play when some over mouse on my image.my code is not working any one can help,if some 1 did this plz let me know the code.thanx in advance

开发者_JAVA百科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>


<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>

This has been tested and is working. May just want to change the cursor when you mouse over in CSS.


Working fine code tested by me You did a mistake in escape characters in embed

<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>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜