2017-07-08 222 views
-4

我想將我的PHP變量顯示爲JavaScript值 這裏是我的PHP和JavaScript代碼。將PHP變量傳遞給javascript值

<?php 
$text = "Rates are subject to change without prior notice"; 
?> 
<script> 
    $('#typewriter').typewriter({ 
     prefix : "*** ", 
     text : ["Rates are subject to change without prior notice"], 
     typeDelay : 50, 
     waitingTime : 1500, 
     blinkSpeed : 200 
    }); 
</script> 

裏面的文本參數我想通過我的PHP變量。

+2

使用'文本:<?PHP的echo $文本; ?>,' – urfusion

+0

使用數組的文本值是否適用於此方法? –

+0

是的,它應該工作。 – urfusion

回答

-3
<?php 
$text = "Rates are subject to change without prior notice"; 
?> 
<script> 
    $('#typewriter').typewriter({ 
     prefix : "*** ", 
     text : [<?php echo $text; ?>], 
     typeDelay : 50, 
     waitingTime : 1500, 
     blinkSpeed : 200 
    }); 
</script> 
+1

由於缺少文本引號,因此不工作。 – Sirko

-3

您可以通過下面的代碼做

 <script> 
      $('#typewriter').typewriter({ 
      prefix : "*** ", 
      text : ["<?php echo $text;?>"], 
      typeDelay : 50, 
      waitingTime : 1500, 
      blinkSpeed : 200 
     }); 
    </script>