简体   繁体   English

php变量到html文件中的javascript变量

[英]php variable to javascript variable in html file

i have php file which has a variable which is calculated from a given data. 我有一个php文件,它有一个根据给定数据计算的变量。 i want to pass this variable to a java script variable which is located in other html file can some one help. 我想将此变量传递给java脚本变量,该变量位于其他html文件中,可以帮助一些人。 i have tried like this but when i tried to display the value nothing comes. 我试过这样但是当我试图显示价值时没有任何结果。 i want the variable to display countdown timer. 我希望变量显示倒数计时器。

<html>
    <body>
        <?php
            require_once "getuser.php"; 
        ?>
        <script>
            var arrival_time = "<?php echo $arrival_time; ?>";
        </script>
    <body>
</html

尝试将其设为php值,而不是像这样的字符串:

var arrival_time = <?php echo $arrival_time; ?>;

Well, I don't know if this is a good practice but this is my method of passing a php value to javascript. 好吧,我不知道这是不是一个好习惯,但这是我将php值传递给javascript的方法。

<input type="hidden" value="<?php echo $arrivaltime; ?>" id="atime">

<script>

    var arrival_time = $("#atime").val();

</script>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM