gpt4 book ai didi

php - "SyntaxError: missing ; before statement"

转载 作者:行者123 更新时间:2023-11-28 02:06:33 25 4
gpt4 key购买 nike

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

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

最佳答案

已更新
更改以下行

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

关于php - "SyntaxError: missing ; before statement",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17699360/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com