正如标题所说,我正在尝试将一些文本附加到 html 中的 textarea,但结果总是有一些涉及 NaN 的奇怪文本出现在 textarea 中......这是我的代码:
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<?php
$_SESSION['currentlocation'] = "combat.php";
?>
<script type="text/javascript">
if(document.getElementById("wrapper") == null) {
window.location = "../index.php";
}
</script>
<textarea id="combatinfo" rows="4" cols="50"></textarea>
<br />
<?php
$_SESSION['currentlocation'] = "combat.php";
if($_SESSION['ambush'] && $_SESSION['flee']) {
for($i = 0; $i < sizeOf($_SESSION['enemies']); $i++) {
echo $_SESSION['enemies'][$i]->rank;
$scaling = 20 - $_SESSION['enemies'][$i] -> luck;
if($_SESSION['enemies'][$i]-> rank >= 20 && $_SESSION['enemies'][$i]-> rank < 40) {
$prob = rand(1, 100);
if($prob <= 100) {
// if($prob <= 75 - $scaling * 3.8) {
if($_SESSION['comboAttack'] < 2) {
$_SESSION['comboAttack'] = 2;
}
$_SESSION['enemies'][$i]->comboAttack = 2;
?>
<script type="text/javascript">
$(document).ready(function() {
$('#combatinfo').append("HELLO WORLD!");
});
</script>
<?php
}
}
else if($_SESSION['enemies'][i]-> rank >= 40 && $_SESSION['enemies'][i]-> rank < 60) {
$prob = rand(1, 100);
if($prob <= 50 - $scaling * 3.8) {
if($_SESSION['comboAttack'] < 3) {
$_SESSION['comboAttack'] = 3;
}
$_SESSION['enemies'][i]->comboAttack = 3;
?>
<script type="text/javascript">
$(document).ready(function() {
var str1 = "Enemy ";
var str2 = "pulls off a 3-hit combo.\n";
var str = str1.concat(str2);
$('#combatinfo').append("HELLO WORLD!");
});
</script>
<?php
}
else if($prob <= 75 - $scaling * 3.8) {
if($_SESSION['comboAttack'] < 2) {
$_SESSION['comboAttack'] = 2;
}
$_SESSION['enemies'][i]->comboAttack = 2;
?>
<script type="text/javascript">
$(document).ready(function() {
var str1 = "Enemy ";
var str2 = "pulls off a 2-hit combo.\n";
var str = str1.concat(str2);
$('#combatinfo').append("HELLO WORLD!");
});
</script>
<?php
}
}
$_SESSION['enemies'][$i] ->attack($i);
}
?>
<button type="button">Defend</button> <button type="button">Flee</button>
<form action="index.php" method="post">
<input type="submit" name="submit" value="Submit" />
</form>
<?php
}
else if(ambush && !flee) {
?>
<button type="button">Defend</button> <button type="button">Flee</button>
<?php
}
if(!ambush && flee) {
?>
<button type="button">Attack</button> <button type="button">Flee</button>
<?php
}
else if(!ambush && !flee) {
?>
<button type="button">Defend</button> <button type="button">Flee</button>
<?php
}
?>
<br />
<select id="selectClone">
<?php
if(sizeOf($_SESSION['playercharacter'] -> clones) == 0) {
?>
<script type="text/javascript">
$(document).ready(function() {
var dropDownMenu = document.getElementById("selectClone");
dropDownMenu.disabled = true;
});
</script>
<option value="Player">Player</option>
<?php
}
else if(sizeOf($_SESSION['playercharacter'] -> clones) == 1) {
?>
<option value="Clone 1">Clone 1</option>
<?php
}
?>
</select>
<div id="player" class="group">asdf</div>
<div id="clone1" class="group">dsfdsfds</div>
<script type="text/javascript">
$(document).ready(function() {
$('.group').hide();
$('#player').show();
$('#selectClone').change(function () {
$('.group').hide();
$('#'+$(this).val()).show();
})
});
</script>
出于某种原因,在文本区域中,我将文本“Enemy #NaN”附加到我想要的文本上。为什么会发生这种情况,我该如何阻止它发生?