代码之家  ›  专栏  ›  技术社区  ›  Pierre

php javascript字符串错误

  •  0
  • Pierre  · 技术社区  · 14 年前

    $other_content = Model_Db::dbSelect($query);
    
            $div_center .= "<table>";
            for($i = 0;$i<sizeof($other_content);$i++) {
                $div_center .= "<tr>";
    
                $div_center .= "<td><a href='#' onclick='changediv('test','0')'>".$other_content[$i]->content_name."</a></td>";
                $temp = "<td><a href='#' onclick='changediv('test','0')'>".$other_content[$i]->content_name."</a></td>";
                die($temp);
    
                $div_center .= "</tr>";
            }
            $div_center .= "</table>";
    

    如您所见,我正在执行die()以查看创建的字符串。 <a href="#" onclick="changediv(" test','0')'>Content Name</a>

    但我得到的却是: <a href="#" onclick="changediv(" test','0')'="">Content Name</a>

    有人能看出这里出了什么问题吗?我有点困惑,因为我真的不知道它从哪里来!

    2 回复  |  直到 14 年前
        1
  •  1
  •   Tobias    14 年前

    $temp = "<td><a href=\"#\" onclick=\"changediv('test', '0')\">" . 
    $other_content[$i]->content_name. "</a></td>";
    

    \”转义字符串中的双引号

        2
  •  0
  •   OverLex    14 年前

    你搞乱了单引号作为双引号的函数解释:

    yours <a href='#' onclick='changediv('test','0')'>
    
    func  <a href="#" onclick="changediv(" test','0')'="">
    

    <a href="#" onclick="changediv('test','0')">
    

    所以单引号和双引号将被正确设置。

    你也必须改变PHP引号