最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

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

programmeradmin1浏览0评论

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>
发布评论

评论列表(0)

  1. 暂无评论