2016-08-20 27 views
0

我仍然試圖習慣JavaScript和PHP所以希望它不是一個noob錯誤。好吧所以在看過這裏發佈的其他帖子之後,我仍然無法找到如何創建新行。我的意思是這樣的下面,試圖添加新行在php內部的JavaScript

1°/ enter image description here 2°/ enter image description here 3°/ enter image description here 4°/ enter image description here

*正如在上方的邊注圖像,你可以看到三個紅色的盒子,在這三個紅色的盒子裏面,就是這個人的呼號和他們正在飛行的飛機。數據正在從XML文件中提取,沒有問題。

但我掙扎的是有1個呼號和1個航空器每行。

 var board = new DepartureBoard (document.getElementById ('test'), { rowCount: 10, letterCount: 40 }); 
     board.setValue (['<?php 
      $EGLL = simplexml_load_file('EGLL.xml'); 
      foreach($EGLL as $info) { 
       echo $info->callsign . " " . $info->aircraft . " " ; 
      } 
      ?>']) 

    </script> 
    <?php 
    file_put_contents("EGLL.xml",   fopen("http://api.vateud.net/online/departures/EGLL.xml", 'r')); 
    ?> 
    <script src="http://code.jquery.com/jquery-latest.js" 
    type="text/javascript"></script> 

所以這是我使用來獲得到基板時的數據的代碼,但是當我添加例如\ n或回聲nl2br它只是返回一個空白網頁。 圖片2顯示了我所看到的,也在那張圖片中,我顯示了我正確放置\ n的位置,並且我還用echo nl2br試了一下,我得到了完全相同的白色屏幕。在這張圖片中,它顯示了所有呼號和飛機的垂直列表,不同於當我刪除\ n其全部水平圖片4希望4鏈接中的1鏈接沒有混淆,但我需要10個代表點才能發佈2或更多:/但希望你明白我想要做什麼。謝謝 - Ciaran

回答

0

您應該發送值以形成一個javascript數組。觀賞爲「位置(每個項目之一):

<?php 
    $EGLL = simplexml_load_file('EGLL.xml'); 
?> 

<script> 
    var board = new DepartureBoard (document.getElementById ('test'), { rowCount: 10, letterCount: 40 }); 
    board.setValue ([ 
    <?php 
     foreach($EGLL as $info) { 
     echo "'" . $info->callsign . " " . $info->aircraft . "'," ; 
     } 
    ?> 
    ]); 
</script> 

這應該生成的JavaScript代碼如下所示,你可以通過查看網頁源代碼中證實:

board.setValue(['AAL7422 B752','AIC234 B738L']); 
+0

多德只是固定它感謝這麼很多http://prntscr.com/c871bp正常工作,因爲我非常感謝它:D –