<?php 
$str = 123;
?>
<script language='javascript'>
alert('<?=$str?>');
</script>

解决方案 »

  1.   

    js 与 PHP 最大的区别是:
        PHP 运行与服务器端,生成 包含有 js的 html发送到用户的浏览器,
         js 运行于客户端,在用户浏览器上执行
    ……
    <body>
    <script language='javascript'>
       alert("<?php echo "hello world"; ?>");
    </script>
    </body>
    ……
    服务器端运行后得到 html:
    ……
    <body>
    <script language='javascript'>
       alert("hello world");
    </script>
    </body>
    ……