简体   繁体   English

“ SyntaxError:丢失; 声明前”

[英]“SyntaxError: missing ; before statement”

Im trying to write code which will add javascript in a variable. 我试图写代码将在变量中添加javascript。 Everything is going find until i get the error "SyntaxError: missing ; before statement" ... I have found out that if i remove a line then it works (i will put // ---- on that line). 一切都会找到,直到出现错误"SyntaxError: missing ; before statement" ...我发现,如果删除一行,那么它将起作用(我将// ----放在该行上)。 Please can someone help? 请有人帮忙吗?

$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 Output: 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();
}

UPDATED 更新
Change below line 在行下更改

$this->archive_name contains a single quote, so you need to escape that first with json_encode $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 = ';

You are concatenating using shorthand ".=" And then concatenating "the normal way". 您使用速记“。=”进行串联,然后使用“普通方式”进行串联。

try this way: 尝试这种方式:

 $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>';

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM