我知道這是一個非常基本的問題,原諒我甚至問,但我似乎無法爲我的生活做好準備。用JQuery替換url中的字符串
我正在使用jQuery從一個圖像src中獲取URL並將其加載到另一個圖像src中,我工作正常。不過,我需要用800x600之類的東西來替換url的100x75部分,這樣才能拉出更大的圖片。
我該怎麼做?
下面是一個例子: 說我在抓住與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 – ajax333221