【发布时间】:2014-03-09 22:58:30
【问题描述】:
我知道这是一个非常基本的问题,请原谅我的提问,但我似乎一辈子都无法正确回答。
我正在使用 JQuery 从一个图像 src 中获取 url,并将其加载到另一个我工作正常的图像 src 中。但是我需要将 url 的 100x75 部分替换为 800x600 之类的内容,以便拉取更大的图像。
我该怎么做?
这是一个例子: 假设我用 jquery 抓取图像源 url,它看起来像这样:http://example.com/images/Something_cool-100x75.png 我需要它看起来像这样:http://example.com/images/Something_cool-800x600.png
jQuery(document).ready(function($) {
// this will pull the image I need
var get_image = $('img.attachment-shop_thumbnail').attr('src');
//this will assign the image I pulled above to where I need it to go but I need to replace the 100x75 in the filename to 800x600
$("#sale_img").attr("src", get_image);
});
所以如果你提供一个答案,你能告诉我它是如何工作的,因为我还需要在其中一些上将 .png 更改为 .jpg .. 只是不确定如何
【问题讨论】:
-
拥有该代码和 jQuery 标签是不公平的,它可以缩小到简单的如何将 stringX 转换为 stringY
标签: javascript jquery