doudang4857 2013-06-17 21:59
浏览 18
已采纳

将文本从对象附加到textarea不起作用

Here is the code:

<?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. 
";

            }

        }
        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. 
";

            }
            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           
}

As the title states I'm trying to append the text in the text-field of an object(skinhead) to a textarea. The above code does not work. However when I replace some code with this:

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

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

This works.

The text in the object is not null, so how come it is not displaying? Thank you for your time.

  • 写回答

1条回答 默认 最新

  • douhoujun9304 2013-06-17 23:16
    关注

    Replace

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

    with

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

    and so on...

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 西门子S7-Graph,S7-300
  • ¥50 用易语言http 访问不了网页
  • ¥50 safari浏览器fetch提交数据后数据丢失问题
  • ¥15 matlab不知道怎么改,求解答!!
  • ¥15 永磁直线电机的电流环pi调不出来
  • ¥15 用stata实现聚类的代码
  • ¥15 请问paddlehub能支持移动端开发吗?在Android studio上该如何部署?
  • ¥20 docker里部署springboot项目,访问不到扬声器
  • ¥15 netty整合springboot之后自动重连失效
  • ¥15 悬赏!微信开发者工具报错,求帮改