关于将PHP值传递给jQuery函数的问题


Issue On Passing PHP Value to jQuery Function

你能看看这段代码,告诉我为什么我不能将变量值从PHP传递到jQuery吗?

<?php
$data = "This is For Test";
?>
<!DOCTYPE html>
  <head>  </head>
  <body>
    <button id="test" type="button" class="btn btn-default">Default</button>
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
    <script>
    var data = "<?php $data; ?>";
    $("#test").on("click",function(){
     alert(data);
    });
    </script>
  </body>
</html> 

感谢

尝试这个

    <script>
        var data = "<?php echo $data; ?>";
      ...

您已错过<?php echo $data; ?>echo

使用

<?php echo $data; ?>