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>
精彩评论