1
2
3
4
5
6
7
8
|
$(document).ready( function (){
<?php $f= "'name'" ?>
var t=<?php echo $f?>;
alert(t)
})
|
或
1
2
3
4
|
<script language= "javascript" >
var t=<?php echo '"sd"' ?>;
alert(t) </script> |
关键是sd两旁既要加单引号还要加上引号否则就会显示“sd is not defined[在此错误处中断] var t=sd;” sd不加引号即为一个变量,之前没定义过该变量,就把他赋值给别的变量,当然会报错