admin管理员组

文章数量:1401826

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

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>

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

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>
Share Improve this question edited Apr 21, 2011 at 18:22 Naftali 146k41 gold badges247 silver badges304 bronze badges asked Apr 21, 2011 at 18:20 Fawad GhafoorFawad Ghafoor 6,2277 gold badges43 silver badges54 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 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>

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>

本文标签: javascriptplaying sound file onMouseOver eventStack Overflow