dpv21589
2013-12-29 11:31
浏览 54
已采纳

如何在JavaScript中回显PHP变量? [重复]

This question already has an answer here:

I need to echo a PHP variable into JavaScript. But I have no experience about JavaScript, I did some research but nothing worked for me.

The code

 function hide() {
   document.getElementById("myDiv").style.display="none";
   <?php echo $myVar; ?>
 }

And the $myVar looks like:

$myVar = "Hi there";
</div>
  • 写回答
  • 好问题 提建议
  • 追加酬金
  • 关注问题
  • 收藏
  • 邀请回答

4条回答 默认 最新

  • duangan1945 2013-12-29 11:33
    已采纳

    you can do like this in js :

    var php_val = '<?php echo $myVar; ?>';
     alert(php_val);
    
    评论
    解决 无用
    打赏 举报
查看更多回答(3条)

相关推荐 更多相似问题