javascript - playing sound when the button is pressed - Stack Overflow

I am trying to make a simple code that if the user clicked the button the sound is played.here is the c

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
Add a ment  | 

1 Answer 1

Reset to default 2

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

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745195447a4616065.html

相关推荐

  • javascript - playing sound when the button is pressed - Stack Overflow

    I am trying to make a simple code that if the user clicked the button the sound is played.here is the c

    6小时前
    20

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信