dougu5847 2016-09-12 11:08
浏览 40
已采纳

Javascript Alert不会提醒字符串?

I'm a bit confused and i'm guessing there's a simple fix so please help.

I have this code (Just a snippet)

$new = "1";

<script language="javascript">
    alert(<?php echo $new; ?>);
</script>

This works fine. It will alert "1". However, if I change $new to

$new = "Hello";

It no longer alerts the value? Any ideas?

  • 写回答

2条回答 默认 最新

  • drne47241 2016-09-12 11:13
    关注

    You're not quoting your string within the Alert function.

    Do this:

    alert('<?php echo $new;?>');
    

    or this, for short

    alert('<?= $new ?>');
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?