0

这是代码:

<?php
$_SESSION['currentlocation'] = "combat.php";

if($_SESSION['ambush'] && $_SESSION['flee']) {

    for($i = 0; $i < sizeOf($_SESSION['enemies']); $i++) {
        $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;
                $_SESSION['enemies'][$i]->attackMessage="Enemy #".strval($i)."pulls off   
         a 2-hit combo. \n";

            }

        }
        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;
                $_SESSION['enemies'][$i]->attackMessage="Enemy #".strval($i)."pulls off 
         a 3-hit combo. \n";

            }
            else if($prob <= 75 - $scaling * 3.8) {
                if($_SESSION['comboAttack'] < 2) {
                    $_SESSION['comboAttack'] = 2;
                }

                $_SESSION['enemies'][$i]->comboAttack = 2;

            }
        }

        if($_SESSION['enemies'][$i] != null) {
           // $_SESSION['enemies'][$i]->attack($i);

           // echo $_SESSION['enemies'][$i]->attackMessage;                
        }    
 ?>                  
<script type="text/javascript">
    $(document).ready(function() {

        $('#combatinfo').append('<?php if($_SESSION['enemies'][$i] != null) echo 
   $_SESSION['enemies'][$i]->attackMessage; ?>');                        
    });
</script>    
<?php      
    }
?>
<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           
}

正如标题所述,我正在尝试将对象(光头)的文本字段中的文本附加到文本区域。上面的代码不起作用。但是,当我用这个替换一些代码时:

 <script type="text/javascript">
    $(document).ready(function() {

        $('#combatinfo').append('<?php if($_SESSION['enemies'][$i] != null) echo 
   "HELLO WORLD!" ?>');                        
    });
</script> 

这行得通。

对象中的文本不为空,怎么不显示呢?感谢您的时间。

4

1 回答 1

0

代替

  $_SESSION['enemies'][$i]->attackMessage="Enemy #".strval($i)."pulls off   
     a 2-hit combo. \n";

$_SESSION['enemies'][$i]->attackMessage="Enemy #".strval($i)."pulls off a 2-hit combo.&#13;&#10;";

等等...

于 2013-06-17T23:16:13.240 回答