javascript - 创建javascript var函数

标签 javascript jquery html

我正在尝试创建一个小型内存游戏...其中时间乘以用户的移动次数...

用户完成所有pars后,javascript运行函数:

 function finish() {
    stopCount();
    var cnt1 = $("#counting").val();
    var tim = $("#timecount").val();
    var totalpuntos = cnt1 * tim; 
    var mensaje = "Congrats! You made <strong>"+cnt1+"</strong> moves in <strong>"+tim+"</strong> seconds, making a total of <strong>"+totalpuntos+"</strong> points!";
    $('#finaldiv').show();
}

在 HTML 中是这样的:

<div id="finaldiv">
<div style="width: 100%; height: 100%; background-image: url('images/overall.png'); z-index:990; position: absolute; top: 0; left: 0;">
<div style="background-color:#fff; margin:100px auto 0 auto; height:300px; width:500px; padding:10px">

<script language="javascript">
document.write (mensaje);
</script>

</div>
</div>
</div>

它确实显示文本框,但不显示消息 :(

如果我将其添加到函数中,它会起作用:

 alert(mensaje);

但我需要它显示在框中而不是在警告消息中,以便可以提交分数...

脚本有什么问题?为什么它不在框中显示消息? :(

最佳答案

我希望你想在最终的 div 中显示分数。为什么不在显示 div 之前填充它。

function finish() {
    stopCount();
    var cnt1 = $("#counting").val();
    var tim = $("#timecount").val();
    var totalpuntos = cnt1 * tim; 
    var message = "Congrats! You made <strong>"+cnt1+"</strong> moves in <strong>"+tim+"</strong> seconds, making a total of <strong>"+totalpuntos+"</strong> points!";
    $('#message').html(message);
    $('#finaldiv').show();
}

编辑: 像这样修改您的 HTML。

<div id="finaldiv">
    <div style="width: 100%; height: 100%; background-image: url('images/overall.png'); z-index:990; position: absolute; top: 0; left: 0;">
        <div id="message" style="background-color:#fff; margin:100px auto 0 auto; height:300px; width:500px; padding:10px">
    </div>
</div>

关于javascript - 创建javascript var函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21549195/

相关文章:

javascript - JS中的P2P文件共享

javascript - 使用 jQuery 延迟 .net 文件上传?

html - 固定宽度的 Div 在 iPad 中呈现太宽

html - 使用 3 个图像的圆 Angular

html - 垂直和水平居中图标和文本

javascript - JS Chrome 插件 - 查找当前事件选项卡中的文本

jquery - 在 JQuery 中截断字符串

javascript - jquery中解除绑定(bind)后如何绑定(bind)点击事件

javascript - 我的网站无法在 android uc 浏览器中运行

javascript - 我正在尝试制作一个简单的程序,每次用户单击按钮时都会增加一个数字