Quiero hacer que cuando haces clic en un botón haga un sonido, probé esto:
<script type="text/javascript"> var audio = new Audio('audio_file.mp3'); </script> <button id="Draw/Chat" onclick="audio.play();" type="button" style="font-weight:bold; background: none rgb(0, 255, 0); border: none; color: rgb(255, 255, 255); box-shadow: none; height: 52px; width: 110px; left: 190px; top: 80px; border-radius: 5px; cursor: pointer; position: absolute;">Draw/Chat</button><!doctype html> <html> <head> <title>Audio</title> </head> <body> <script> function play() { var audio = document.getElementById("audio"); audio.play(); } </script> <input type="button" value="PLAY" onclick="play()"> <audio id="audio" src="https://interactive-examples.mdn.mozilla.net/media/cc0-audio/t-rex-roar.mp3"></audio> </body> </html>Prueba este código, por favor
No use un punto y coma en la función onclick:
<script type="text/javascript"> var audio = new Audio('audio_file.mp3'); </script> <button id="Draw/Chat" onclick="audio.play()" type="button" style="font-weight:bold; background: none rgb(0, 255, 0); border: none; color: rgb(255, 255, 255); box-shadow: none; height: 52px; width: 110px; left: 190px; top: 80px; border-radius: 5px; cursor: pointer; position: absolute;">Draw/Chat</button>