我正在尝试创建一个小型内存游戏...其中时间乘以用户的移动次数...
用户完成所有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/