Last active
January 1, 2016 04:39
-
-
Save allenfantasy/8092963 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
audio { | |
display: none; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta charset=utf-8 /> | |
<title>JS Bin</title> | |
</head> | |
<body> | |
<!-- support multi browser --> | |
<audio controls="controls"> | |
<source src="http://www.w3school.com.cn/i/horse.ogg" type="audio/ogg"> | |
<source src="http://www.w3school.com.cn/i/horse.mp3" type="audio/mpeg"> | |
Your browser does not support the audio element. | |
</audio> | |
<button>Click me to play!</button> | |
</body> | |
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
window.onload = function() { | |
var button = document.getElementsByTagName("button")[0]; | |
var audio = document.getElementsByTagName("audio")[0]; | |
button.onclick = function() { | |
audio.play(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment