我无法弄清楚如何在onclick中正确放置php变量,这样它就不会引起某种错误:(我不知道要走哪条路。似乎只要有引号,就会导致这个错误。也许还有其他字符会导致问题。页面会加载,就在我按下“infoIconButtonImage”时发生错误。这是我试过的:
while($stmt->fetch())
{
$shortDescription = preg_replace("/\r\n|\r|\n/",' ', $shortDescription);
$longDescription = preg_replace("/\r\n|\r|\n/",'<br/>', $longDescription);
$price = preg_replace("/\r\n|\r|\n/",' ', $price);
echo "<div class=\"iconButtonContainer\"><img class=\"infoIconButtonImage\" src=\"Images/item_info_button_image.png\" alt=\"\" onclick=\"showMoreItemInfo(this, '$price', '$imageUrl', '$shortDescription', '$longDescription')\"></div>";
}
我已经拿出了我认为不必要的部分代码。这是数据和错误:
答案 0 :(得分:0)
尝试
echo "<div class=\"iconButtonContainer\"><img class=\"infoIconButtonImage\" src=\"Images/item_info_button_image.png\" alt=\"\" onclick=\"showMoreItemInfo(this, '" . $price . "', '" . $imageUrl . "', '" . $shortDescription . "', '" . $longDescription . "')\"></div>";