admin管理员组文章数量:1415120
I am trying to make a simple code that if the user clicked the button the sound is played.
here is the code:
<script>
function play(){
$("body").append("<embed src='play.mp3' autostart='true' loop='false' width='2' height='0'></embed>");
}
</script>
<form action="" method="post">
<input type="button" onclick="play()" value="click">
</form>
I am trying to make a simple code that if the user clicked the button the sound is played.
here is the code:
<script>
function play(){
$("body").append("<embed src='play.mp3' autostart='true' loop='false' width='2' height='0'></embed>");
}
</script>
<form action="" method="post">
<input type="button" onclick="play()" value="click">
</form>
Share
Improve this question
asked Aug 17, 2013 at 13:04
Mj JamMj Jam
1734 gold badges6 silver badges16 bronze badges
1 Answer
Reset to default 2Try this. Should work.
<!DOCTYPE html>
<html>
<head>
<script language="javascript">
function playIt()
{
document.getElementById("embed").innerHTML="<embed src='play.mp3' autostart=true loop=false volume=100 hidden=true>";
return true;
}
</script>
</head>
<body>
<form action="" method="post">
<button type="button" onclick="playIt()">play</button>
<div id="embed"></div>
</form>
</body>
</html>
本文标签: javascriptplaying sound when the button is pressedStack Overflow
版权声明:本文标题:javascript - playing sound when the button is pressed - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745195447a2647112.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论