我试图编写将在变量中添加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 £'.$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();
}
答案 0 :(得分: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 £'.$this->archive_price.' inc Packagin' ).';
}
function image_'.$this->archive_id.'_fullsize() {
document.getElementById("gallery").innerHTML = ';
答案 1 :(得分: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>';