那个头衔满口...... 嘿人!我在学校的网络应用程序项目中遇到了这个错误,在过去一周左右尝试了其他方法后,我还没能通过。我希望有人能够抓住我能做到的事情......
好的,所以这里的代码我认为是问题的根源:
echo"<div class='RightSidebar'> <button id='AtkBtn' type='button' onclick='attack(".$currentTurn.");'><b>Attack</b></button></a>\n";
以下是Javascript功能:
function attack(turn)
{
if(turn == 1 )
{alert('It is not your turn!!');}
else
{
document.getElementById.("TextLog").innerHTML = "You attack the enemy!";
}
}
(这是名为&#34的文件中的唯一代码; BattleMethods.js&#34 ;;开头体标记上方的脚本标记表明我们将使用此文件。如果我也可以复制该行它有助于...) 尚未通过效果(即对敌人的健康产生影响)。我想首先运行它,然后编写代码。
现在有了这些信息,我需要做以下事情:
1)玩家点击右侧边栏div中的攻击按钮
2)战斗屏幕div下方的TextLog div显示敌人显示当前相关信息(即:&#34;你攻击敌人!&#34;)
3)客户端变量适当更新(userHP,currentTurn等)
就是这样。如果我能弄清楚当玩家点击攻击按钮时不允许该功能做出反应,我可以让变量更新没有问题。我在商品商店做过类似的事情并且工作正常。所以我真的很茫然。我希望这是足够的信息!任何帮助深表感谢。
脚本所在的HTML:
echo"<!DOCTYPE html>\n";
echo"<html>\n";
echo"<head>\n";
echo"<title>SlateKeeper -- BATTLEROOM</title>\n";
echo"<meta name='viewport' content='minimum-scale=0.98; maximum-scale=5;initial- scale=0.98;user-scalable=no;width=1024'>\n";
echo"<link rel='stylesheet' type = 'text/css' href='CSS/battleTowersStyles.css'>\n";
echo"<script language= 'Javascript' type = 'text/javascript' src='Javascript/BattleMethods.js'></script>\n";
echo"<style>\n";
echo" body {background-color: #3b4870}\n";
echo"</style>\n";
echo"</head>\n";
答案 0 :(得分:0)
请参阅我对此代码所做的以下更改。它工作正常。
这些是javascript的变化。
function attack(turn)
{
if(turn == 1 )
{
alert('It is not your turn!!');
}
else
{
document.getElementById('TextLog').innerHTML = "You attack the enemy!";
}
}
PHP代码是
$turn = 0;
echo"<div class='RightSidebar'> <button id='AtkBtn' type='button' onclick='attack($turn)'><b>Attack</b></button></a>\n";
你在线上犯了错误,
document.getElementById.("TextLog").innerHTML = "You attack the enemy!";
应该是
document.getElementById("TextLog").innerHTML = "You attack the enemy!";