Javascript变量问题 [英] Javascript variable issue
问题描述
您好,我正在进行文字冒险尝试学习javascript,并且我在向页面显示整数值时遇到问题。例如,在波纹管代码中,我想在您键入攻击时显示用户HP。但页面上没有显示任何内容。我做错了什么?
<!DOCTYPE html PUBLIC - // W3C // DTD XHTML 1.0 Transitional // ENhttp://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">
< html xmlns =http://www.w3.org/1999/xhtml>
< head>
< script src =scripts / jquery.jstype =text / javascript>< / script>
< meta http-equiv =Content-输入content =text / html; charset = utf-8/>
< title> The Game !!< / title>
< / head>
< body>
< script>
var userHP = 500;
var hits = Math.floor(Math.random()* 100) - mobHP;
$(文件).ready(function(){
$(#compass)。fadeIn(3000);
$(#message_begin)。fadeIn(3000);
$(#area_main)。fadeIn(3000);
$(#command_line)。fadeIn(3000);
$(form)。submit(function(){
var input = $(#command_line ).val();
//
//帮助
//
if(input.indexOf(help)> -1){
if(input ==help){
$(#message_help)。clone()。insertBefore(#placeholder)。 fadeIn(1000);
}
}
//
//结束帮助
//
else if(input.indexOf(enter)> -1){
if(input ==enter){<
$(#message_enter)。clone()。insertBefore(#placeholder)。fadeIn(1000);
}
} < br $>
//
//结束帮助
//
else if(input.indexOf(attack) > -1){
if(input ==attack){
$(#message_attack)。clone()。insertBefore(#placeholder ).fadeIn(1000);
}}
< / script>
< p id =message_attack>< script> userHP< / script>你攻击< / p>
< form>
< input type =textid = command_linesize =50autofocus =autofocus/>
< / form>
< script type =text / javascriptsrc =scripts / game.js>< / script>
< / body>
< / html>
Hello, i'm making a text adventure to try to learn javascript and im having problems with displaying integer values to my page. for example in the bellow code i want to display the users HP when you type attack. but nothing shows on the page. what am i doing wrong?
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<script src="scripts/jquery.js" type="text/javascript"></script>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>The Game!!</title>
</head>
<body>
<script>
var userHP = 500;
var hits = Math.floor(Math.random() * 100) - mobHP;
$(document).ready(function() {
$("#compass").fadeIn(3000);
$("#message_begin").fadeIn(3000);
$("#area_main").fadeIn(3000);
$("#command_line").fadeIn(3000);
$("form").submit(function() {
var input = $("#command_line").val();
//
//help
//
if (input.indexOf("help") > -1) {
if (input == "help") {
$("#message_help").clone().insertBefore("#placeholder").fadeIn(1000);
}
}
//
//end help
//
else if (input.indexOf("enter") > -1) {
if (input == "enter") {
$("#message_enter").clone().insertBefore("#placeholder").fadeIn(1000);
}
}
//
//end help
//
else if (input.indexOf("attack") > -1) {
if (input == "attack"){
$("#message_attack").clone().insertBefore("#placeholder").fadeIn(1000);
}}
</script>
<p id="message_attack"><script>userHP</script>you attack</p>
<form >
<input type="text" id="command_line" size="50" autofocus="autofocus" />
</form>
<script type="text/javascript" src="scripts/game.js"></script>
</body>
</html>
推荐答案
(document).ready(function(){
(document).ready(function() {
(#compass)。fadeIn(3000);
("#compass").fadeIn(3000);
(#message_begin)。fadeIn(3000);
("#message_begin").fadeIn(3000);
这篇关于Javascript变量问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!