更改来自第三方服务器的图像

Changing an image from third party server

本文关键字:服务器 图像 第三方      更新时间:2024-05-29

我正在寻找一种方法来更改我无法访问的脚本(托管在第三方服务器上)上的图像。

我想显示的图像在href中,但img src显示的是缩略图版本。

我假设我需要某种jQuery脚本,用附加的版本替换每个实例(可能不止一个)。

div为:

<div id="imagezoomcontainer">
<a target="_blank" class="chatlink" href="goodimage.jpg">
<span></span>
<img src="badimage.jpg" align="middle" border="0" height="100" width="100"></a>
</div>

我希望我能访问服务器——这会节省很多时间!

这是一个基本示例,它将在页面加载时进行更改。

$(document).ready(function(){
        $("#imagezoomcontainer img").attr("src",$("#imagezoomcontainer .chatlink").attr("href"));
    });

正如您所猜测的,您需要浏览所有图像并进行更改。您可以使用$.each循环来执行类似的操作:

$(document).ready(function(){
   $.each("#imagezoomcontainer img", function(){
        $(this).attr("src", $(this).parent().children(".chatlink").attr("href");
   });
});

尝试

$(".chatlink").click(function(){
  e.preventDefault();
  var thisObj = $(this);
  thisObj.next("img").attr("src", thisObj.attr("href"));
});