1

我正在尝试编写将在变量中添加 javascript 的代码。一切都会找到,直到我收到错误"SyntaxError: missing ; before statement"...我发现如果我删除一行,那么它就可以工作(我将把 // ---- 在那一行上)。请问有人可以帮忙吗?

$this->paint_javascript_function_text .= '
    function image_'.$this->archive_id.'_rollover (){
        document.getElementById("details").innerHTML = "'.$this->archive_name.'<br />'.$this->archive_dimensions.' - Price &#163;'.$this->archive_price.' inc Packaging";
    }
    function image_'.$this->archive_id.'_fullsize (){
        document.getElementById("gallery").innerHTML = ';
        $this->paint_javascript_function_text .= "'";

        $this->paint_javascript_function_text .= '<table width="100%" height="400"border="0" align="center"><tr><td align="right" valign="middle">';
        if($this->archive_id == 1) {
            $this->paint_javascript_function_text .= '<img src="images/paint_gallery/prev_faded.png" border="0" class="paint_nav" />';
        }
        else
        {
            $prev = $this->archive_id - 1;
            $this->paint_javascript_function_text .= '<a href="#"><img src="images/paint_gallery/prev.png" border="0" class="paint_nav" onclick="javascript:image_'.$prev.'_fullsize();" /></a>';
        }

        $this->paint_javascript_function_text .= '</td><td width="400px" height="523px" align="center" valign="middle">'.$newimage.'<br /><a href="#" class="paint_link" onclick="javascript:return_to_small_images();">Back to Gallery</a></td><td align="left" valign="middle">';
        if($total_num == $this->archive_id){
            $this->paint_javascript_function_text .= '<img src="images/paint_gallery/next_faded.png" border="0" class="paint_nav" />';
        }
        else
        {
            $next = $this->archive_id + 1;
            $this->paint_javascript_function_text .= '<a href="#"><img src="images/paint_gallery/next.png" border="0" onclick="javascript:image_'.$next.'_fullsize();" class="paint_nav" /></a>';
        }

        $this->paint_javascript_function_text .= '</td></tr></table>';

        // ---- $this->paint_javascript_function_text .= '<center><span class="paintings_title">'.$this->archive_name.' - '.$this->archive_dimensions.' - '.$this->archive_price.' inc P&P</span><br /><a href="basket.php?addprint='.$this->archive_id.'"><img src="images/shop/basket_button.png" border="0" /></a></center>';
        $this->paint_javascript_function_text .= "';
            ";
        $this->paint_javascript_function_text .= '
            $("#main_content").hide();
            $("#gallery").show();
            $("#paint_nav").hide();
    }';

HTML 输出:

function image_4_fullsize (){
    document.getElementById("gallery").innerHTML = '<table width="100%" height="400" border="0" align="center"><tr><td align="right" valign="middle"><a href="#"><img src="images/paint_gallery/prev.png" border="0" class="paint_nav" onclick="javascript:image_3_fullsize();" /></a></td><td width="400px" height="523px" align="center" valign="middle"><img src="images/print_gallery/Countrymans Kitchen.jpg" /><br /><a href="#" class="paint_link" onclick="javascript:return_to_small_images();">Back to Gallery</a></td><td align="left" valign="middle"><a href="#"><img src="images/paint_gallery/next.png" border="0" onclick="javascript:image_5_fullsize();" class="paint_nav" /></a></td></tr></table><center><span class="paintings_title">Countryman's Kitchen -  -  inc P&P</span><br /><a href="basket.php?addprint=4"><img src="images/shop/basket_button.png" border="0" /></a></center>';

    $("#main_content").hide();
    $("#gallery").show();
    $("#paint_nav").hide();
}
4

2 回答 2

1

更新
更改以下行

$this->archive_name包含一个单引号,所以你需要先用json_encode

$this->paint_javascript_function_text .= 'function image_'.$this->archive_id.'_rollover () {
  document.getElementById("details").innerHTML = '.json_encode( $this->archive_name.'<br />'.$this->archive_dimensions.' - Price &#163;'.$this->archive_price.' inc Packagin' ).';
}
function image_'.$this->archive_id.'_fullsize() {
  document.getElementById("gallery").innerHTML = ';
于 2013-07-17T12:18:11.823 回答
0

您正在使用速记“。=”连接,然后连接“正常方式”。

试试这种方式:

 $this->paint_javascript_function_text = $this->paint_javascript_function_text . '<center><span class="paintings_title">'.$this->archive_name.' - '.$this->archive_dimensions.' - '.$this->archive_price.' inc P&P</span><br /><a href="basket.php?addprint='.$this->archive_id.'"><img src="images/shop/basket_button.png" border="0" /></a></center>';
于 2013-07-17T12:12:01.353 回答