gpt4 book ai didi

php - 在 JavaScript onmouseover 中转义 PHP 代码

转载 作者:行者123 更新时间:2023-11-30 08:52:16 26 4
gpt4 key购买 nike

我很难理解如何在 php block 内的 JavaScript 事件中管理单引号和双引号。

这是代码:

<?php
$mainImagePath = '';
$galleryImages = $this->getGalleryImages();
if (count($galleryImages) > 0) {
$gallery = '<div class="more-views">';
$gallery .= '<h2>' . $this->__('More Views') . '</h2>';
$gallery .= '<ul>';
foreach ($galleryImages as $_image) {
if ($_image->getFile() == $_product->getData('small_image')) {
$mainImagePath = $this->getGalleryUrl($_image);
}
$gallery .= '<li>'
. '<a href="' . $this->helper('catalog/image')->init($this->getProduct(), 'image', $_image->getFile()) . '" '
. 'rel="popupWin:\'' . $this->getGalleryUrl($_image) . '\', useZoom: \'cloudZoom\', smallImage: \'' . $this->getCloudImage($this->getProduct(), $_image) . '\'" class="cloud-zoom-gallery" title="' . $this->htmlEscape($_image->getLabel()) . '" onmouseover="$(\'image\').src = "'.$this->helper('catalog/image')->init($this->getProduct(), 'thumbnail', $_image->getFile())->resize(256).'"; return false;">'
. '<img src="' . $this->helper('catalog/image')->init($this->getProduct(), 'thumbnail', $_image->getFile())->resize(56) . '" width="56" height="56" alt="' . $this->htmlEscape($_image->getLabel()) . '" />'
. '</a></li>';
}
$gallery .= '</ul></div>';
}
?>

问题是 onmouseover 事件,它有一个 .src 方法,该方法期望值在双引号内,但是在该字符串内放置双引号会破坏其余部分.

我已经尝试将所需的值放入一个变量中并回显该变量,但这也没有用。

我怎样才能在那里正确转义引号?

最佳答案

onmouseover="$(\'image\').src = "'.$this->helper('catalog/image')->init($this->getProduct(), 'thumbnail', $_image->getFile())->resize(256).'"; return false;">

使用单引号

onmouseover="$(\'image\').src = \''.$this->helper('catalog/image')->init($this->getProduct(), 'thumbnail', $_image->getFile())->resize(256).'\'; return false;">

关于php - 在 JavaScript onmouseover 中转义 PHP 代码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16833080/

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