我在制作基本增量“点击器”游戏时遇到问题 每次我点击按钮时按钮都会消失但分数会弹出
的index.html
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<link rel="stylesheet" type="text/css" href="css/interface.css" />
<title>Face Clicker</title>
</head>
<body>
<script type="text/javascript" src="js/main.js"></script>
<span id="faces"/>
<button id="Face" onClick="faceClick(1)"><img src="images/face.png"><p align="center" style="line-height:-200em">Click Me!</p></button>
</body>
</html>
main.js
var faces = 0;
function faceClick(number) {
faces = faces + number;
document.getElementById("faces").innerHTML = faces;
};
答案 0 :(得分:1)
var faces = 0;
function faceClick(number) {
faces = faces + number;
document.getElementById("faces").innerHTML = faces;
};
&#13;
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<link rel="stylesheet" type="text/css" href="css/interface.css" />
<title>Face Clicker</title>
</head>
<body>
<script type="text/javascript" src="js/main.js"></script>
<span id="faces"> </span>
<button id="Face" onClick="faceClick(1)"><img src="images/face.png"><p align="center" style="line-height:-200em">Click Me!</p></button>
</body>
</html>
&#13;
固定。
你忘了关闭<span>
您的<span />
并未以此方式关闭。你需要关闭像<span></span>
答案 1 :(得分:0)
试试这个:
<span id="faces"><span/>
而不是:
<span id="faces"/>
答案 2 :(得分:0)
问题是你在宣布
<span id="faces" />
但你必须将其声明为
<span id="faces"></span>
span标记未正确关闭
var faces = 0;
function faceClick(number) {
//alert(number);
faces = faces + number;
document.getElementById("faces").innerHTML = faces;
};
debugger
&#13;
<span id="faces"></span>
<button id="Face" onClick="faceClick(1)"><img src="images/face.png"><p align="center" style="line-height:-200em">Click Me!</p></button>
&#13;
希望有所帮助