首页 > 解决方案 > 如何在javascript中编写字符串和回显的比较代码?

问题描述

<script>
 if (<? echo $temp =="xxxxx" ?>){  //the problem is in the if clause
console.log("yyy");
}
<script>

它在控制台中说“)”的意外标记

标签: javascriptphpcodeigniter

解决方案


你混合 php 和 javascript。我猜你想在客户端进行比较。试试这个代码:

<script>
    var tmp = "<? echo $temp ?>";
    if (tmp =="xxxxx" ) {
        console.log("yyy");
    }
<script>

推荐阅读