如何在php代码中调用javascript函数

时间:2017-11-04 04:58:43

标签: javascript php

我有一个关于如何使用if else语句调用php脚本中的javascript函数的问题

这是我的PHP代码

if (!$output) {

    !! here i want to call a javascript function !!



// $status = "Server has been shutdown!";
// $date = date('Y-m-d H:i:s');
 $serverDate = time();
 $serverStatus = 0;



} else {

这里是我要调用的javascript我只是想让你们知道我添加了函数OfflineStatus(){}; idk如果能调用VAR变量?

  function OfflineStatus() {
     var nodes = [
      { hostname: "", status: "OFFLINE", address: "", icon: "tasks" },
      { hostname: "", status: "OFFLINE", address: "", icon: "tasks" }
    ];
    }

原始代码是这个

 var nodes = [
      { hostname: ", status: "OFFLINE", address: "", icon: "tasks" },
      { hostname: "", status: "OFFLINE", address: "", icon: "tasks" }
    ];

1 个答案:

答案 0 :(得分:0)

您可以使用php在<script></script>

中生成javascript字符串
<script>
<?php
  if (!$output) {
    echo "OfflineStatus();";
  }
?>
</script>