显示分数后按钮消失

时间:2015-09-27 07:57:19

标签: javascript html dom

我在制作基本增量“点击器”游戏时遇到问题 每次我点击按钮时按钮都会消失但分数会弹出

的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;
};

3 个答案:

答案 0 :(得分:1)

&#13;
&#13;
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;
&#13;
&#13;

固定。
你忘了关闭<span> 您的<span />并未以此方式关闭。你需要关闭像<span></span>

这样的跨度

答案 1 :(得分:0)

试试这个:

<span id="faces"><span/>

而不是:

<span id="faces"/>

答案 2 :(得分:0)

问题是你在宣布

   <span id="faces" />

但你必须将其声明为

   <span id="faces"></span>

span标记未正确关闭

&#13;
&#13;
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;
&#13;
&#13;

希望有所帮助