我的图片来源中有网址 像这样 我在数组中得到这个值,例如。 img [0]。所以可以用php或jquery
来改变它http://feedtest.tecontent.com/image.php/cover.jpg?image=/covers/cover.jpg&width=400&height=571&quality=90
我希望在加载时使用JQuery更改其高度和宽度,使用jquery
答案 0 :(得分:0)
如果远程站点接受新宽度并根据您的需要显示图像,您可以做这样的事情
img[0] = preg_replace( array('/width=[0-9][0-9][0-9]/i', '/height=[0-9][0-9][0-9]/i'), array('width=200','height=200'), $content);
答案 1 :(得分:0)
第一步:我们可以写一个简单的函数来自由使用:
function replaceUrlParam(url, paramName, paramValue){
if(paramValue == null)
paramValue = '';
var pattern = new RegExp('\\b('+paramName+'=).*?(&|$)')
if(url.search(pattern)>=0){
return url.replace(pattern,'$1' + paramValue + '$2');
}
return url + (url.indexOf('?')>0 ? '&' : '?') + paramName + '=' + paramValue
}
Step-2:然后在我们需要的时候调用该函数:
//considering the below URL:
var myUrl = 'http://feedtest.tecontent.com/image.php/cover.jpg?image=/covers/cover.jpg&width=400&height=571&quality=90';
replaceUrlParam(myUrl,'width',999999); //adjust width as per our need;
replaceUrlParam(myUrl,'height',88888); //adjust height as per our need;