我正在开发一个项目,以便在选择缩略图并且工作正常时将缩略图图像交换为更大的图像但是,我现在希望最终用户能够单击更大的图像以在 jquery.lightbox 中显示它- 0.5。问题是在选择缩略图后加载的图像没有href。我希望我可以使用 onclick 事件将图像 src 传递给 href,但我不知道如何使它工作。
这是我的代码
<script type="text/javascript">
function swaphref(image) {
document.getElementById('image').setAttribute('href', this.src);
//window.alert(document.getElementById('image').src);
}
</script>
<body>
<div class="productimage" id="gallery"><a onclick="swaphref(this)"><img id="image" img src="product_images/<?php echo $targetID; ?>/<?php echo $targetID; ?>.jpg" width="253" height="378" border="0" /></a></div>
</body>