我如何在按钮菜单上添加声音
How i put a sound on my buttons menu
HTML:
<!DOCTYPE html>
<head>
<meta charset="UTF-8">
</head>
<body>
<div class="buttons" >
<li><pre><strong><a href="home.html">Home</a></strong> </pre></li>
</div>
</body>
CSS:
.buttons{
font-size:16px;
position:fixed;
bottom:217px;
left:183px;
}
这是我的代码,没有任何声音,我怎样才能在上面输入声音?
您可以使用这个 jQuery 代码:
$(document).ready(function() {
var audioElement = document.createElement('audio');
audioElement.setAttribute('src', 'audio.mp3');
audioElement.setAttribute('autoplay', 'autoplay');
//audioElement.load()
$.get();
audioElement.addEventListener("load", function() {
audioElement.play();
}, true);
$('.play').click(function() {
audioElement.play();
});
$('.pause').click(function() {
audioElement.pause();
});
});
和 HTML 控制器:
<div class="play">Play</div>
<div class="pause">Stop</div>
下次请使用搜索:
Play an audio file using jQuery when a button is clicked
HTML:
<!DOCTYPE html>
<head>
<meta charset="UTF-8">
</head>
<body>
<div class="buttons" >
<li><pre><strong><a href="home.html">Home</a></strong> </pre></li>
</div>
</body>
CSS:
.buttons{
font-size:16px;
position:fixed;
bottom:217px;
left:183px;
}
这是我的代码,没有任何声音,我怎样才能在上面输入声音?
您可以使用这个 jQuery 代码:
$(document).ready(function() {
var audioElement = document.createElement('audio');
audioElement.setAttribute('src', 'audio.mp3');
audioElement.setAttribute('autoplay', 'autoplay');
//audioElement.load()
$.get();
audioElement.addEventListener("load", function() {
audioElement.play();
}, true);
$('.play').click(function() {
audioElement.play();
});
$('.pause').click(function() {
audioElement.pause();
});
});
和 HTML 控制器:
<div class="play">Play</div>
<div class="pause">Stop</div>
下次请使用搜索:
Play an audio file using jQuery when a button is clicked