【问题标题】:pass PHP variable to javascript value [duplicate]将PHP变量传递给javascript值[重复]
【发布时间】:2017-07-08 07:16:50
【问题描述】:

我想将我的 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 变量。

【问题讨论】:

  • 使用text :&lt;?php echo $text; ?&gt;,
  • 使用数组的文本值是否适用于这种方法?
  • 是的,它应该可以工作。
  • 这个问题在这里问了一百万次

标签: javascript php json


【解决方案1】:
<?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>

【讨论】:

  • 因为文本缺少引号而无法使用。
【解决方案2】:

您可以使用以下代码来完成

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

【讨论】:

    猜你喜欢
    • 2014-01-11
    • 2016-02-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-04-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多