I have a JS Function:
function zoom(now) {
document.getElementById("popup").style.display = "block";
document.getElementById("photos").style.backgroundImage = "url('" + now + "')";
}
And I have echoed in php, which has onclick function
echo
"<td style='background: url(" . $row['thumbnails'] . ")' onclick='zoom(" . $row['imagelink'] . ")'></td>";
So it says
Uncaught SyntaxError: Unexpected token ILLEGAL.
When I put just 1.jpg in php instead of imagelink it works. but not with $row['imagelink']. I absolutely need to change background image, so please if anyone can help or give me a different option in JS, PHP, HTML only. Thank you
您在php中缺少引号,因此它会生成无效的HTML
echo '<td style="background: url(' . $row['thumbnails'] . ')" onclick="zoom(\'' . $row['imagelink'] . '\')"></td>';
I assume the $row['imagelink'] variable contains a filename string, eg 'file.jpeg'. When echoed in PHP, the HTML onclick attribute would be
The quotes around file.jpeg are missing, so the PHP should be:
"<td style='background: url(" . $row['thumbnails'] . ")' onclick='zoom(\"" . $row['imagelink'] . "\")'></td>";
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.