我想获得一些按钮来处理声音没有成功。对于我使用的页面我有它设置为这样:有音频播放点击
// javascript file for gun tutorial//
window.onload=function()
{
\t var extraAmmo = 210;
\t var maxAmmo = 30;
\t var currentAmmo = maxAmmo;
\t
\t var extraAmmoHud = document.getElementById("extra-ammo");
\t var currentAmmoHud = document.getElementById("current-ammo");
\t
\t var shootButton = document.getElementById("shoot-button");
\t var unloadButton = document.getElementById("unload-button");
\t var reloadButton = document.getElementById("reload-button");
\t \t refreshScreen();
\t \t
\t shootButton.onclick=function()
\t {
\t \t if(currentAmmo > 0)
\t \t {
\t \t \t currentAmmo--;
\t \t \t refreshScreen();
\t \t }
\t }
\t unloadButton.onclick=function()
\t {
\t if (currentAmmo > 0)
\t \t {
unloadTimer = setTimeout(unloadButton.onclick, 150)
\t currentAmmo--;
\t refreshScreen();
\t }
\t \t else unloadTimer = null;
\t }
\t reloadButton.onclick=function()
\t {
\t \t var difference = getDifference();
\t \t if(extraAmmo >= difference)
\t \t {
\t \t \t currentAmmo += difference;
\t \t \t extraAmmo -= difference;
\t \t }
\t \t else
\t \t {
\t \t \t currentAmmo += extraAmmo;
\t \t \t extraAmmo -= extraAmmo;
\t \t }
\t \t refreshScreen();
\t \t
\t \t function getDifference()
\t \t {
\t \t \t return maxAmmo -currentAmmo;
\t \t }
\t }
\t function refreshScreen()
\t {
\t \t extraAmmoHud.innerHTML="Extra Ammo: " + extraAmmo;
\t \t currentAmmoHud.innerHTML="Current Ammo: " + currentAmmo;
\t }
}
<!DOCTYPE HTML>
<html>
<head>
<meta charset="UTF-8">
<title>Gun Tutorial</title>
<link rel="stylesheet" type="text/css" href="css/style.css"/>
<script src="js/gun.js"></script>
<audio src="sounds/GunShot.mp3"></audio>
<audio src="sounds/GunShotFullAuto.mp3"></audio>
<audio src="sounds/GunCockingFast.wav"></audio>
</head>
<body>
\t <div id="wrapper">
\t <header id="header">
\t \t <h1>Welcome to the Gun Show</h1>
\t </header>
\t <div id="content"></div>
\t <form>
\t <div id="boxobuttons">
\t \t <input type="button" value="Shoot" id="shoot-button" />
\t \t <input type="button" value="Unload" id="unload-button" />
\t \t <input type="button" value="Reload" id="reload-button" />
\t </div>
\t
\t \t <div id="ammo-count">
\t \t \t <p id="current-ammo"></p>
\t \t \t <p id="extra-ammo"></p>
\t \t </div>
\t </form>
\t <footer>
\t </footer>
\t </div>
</body>
</html>
我想看看我是否需要有声音充当一个变量,每个变量可再插入到不同的变量(shootButton,unloadButton和reloadButton)中,还是我必须完全分开做一些事情?
感谢输入托马斯,给我一个时刻,我会尽快与你,告诉你,如果它工作。 –
它看起来像一个不,暂时,我想说我发现了问题,因为它可能不喜欢音频文件在它自己的文件夹(声音),所以我要将它们移动到打开index.html查看是否有效。 –
将它移动到open.html与index.html工作,现在做同样的卸载和重新加载 –