gpt4 book ai didi

php - 使用 Javascript 将 href 文本替换为其他内容

转载 作者:行者123 更新时间:2023-11-28 20:27:03 24 4
gpt4 key购买 nike

如何替换“echo ucwords($row2[mainImage1]);”在下面标签的 href 属性中使用“echo $row2[selectionThumb3];”使用 Javascript 从下面标签的 src 属性中获取?

这是我的代码的外观:

    <img class="thumbNotSelected" src="../images/ThumbSelection/<?php echo $row2[selectionThumb3]; ?>.jpg"  />

<div class="mainImage magnify">
<a href="../images/MainImage/<?php echo ucwords($row2[mainImage1]); ?>.jpg" rel="lightbox" title="<?=$row2[name]?>">
<img class="mainImage small" src="../images/MainImage/<?php echo $row2[mainImage1]; ?>.jpg" /></a>
</div>

添加我当前的 Javascript:

$('#thumbs').delegate('img', {
click: function(){
$('.mainImage').attr('src',$(this).attr('src').replace('ThumbSelection','MainImage').replace('selectionThumb','mainImage')); //here I replace the src of the Main Image to match the selected thumbnail.
var $this = $(this),
index = $this.index();
$("#thumbs img").removeClass('thumbSelected');
$this.addClass('thumbSelected');

}});

用户可以单击多个拇指。主图像点击其Thumb后会加载相应的图片。但是,(用于灯箱)永远不会改变以适应新加载的图片,并且灯箱始终使用相同的图像而不是用户单击的图像。谢谢!

最佳答案

$('.mainImage a').attr('href', $('.thumbNotSelected').attr('src'));

应该做你需要的事情。

关于php - 使用 Javascript 将 href 文本替换为其他内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17179791/

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