php变量赋值给js

$(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不加引号即为一个变量,之前没定义过该变量,就把他赋值给别的变量,当然会报错
posted @ 2012-04-23 15:01  break_happy  Views(15531)  Comments(0Edit  收藏  举报