标签:
$(document).ready(function(){ <?php $f="‘name‘"?> var t=<?php echo $f?>; alert(t) })
或
<script language="javascript" > var t=<?php echo ‘"sd"‘?>; alert(t) </script>
关键是sd两旁既要加单引号还要加上引号否则就会显示“sd is not defined[在此错误处中断] var t=sd;” sd不加引号即为一个变量,之前没定义过该变量,就把他赋值给别的变量,当然会报错
php变量赋值给js
原文地址:http://www.cnblogs.com/lonelyxmas/p/4210699.html