jQuery Wildcare 图片来源
jQuery Wildcare Image Source
我正在尝试更改图像 src 的一部分以进行 A/B 测试,但在阅读了大量文章后,我变得越来越困惑。这是图像 URL(它是结果列表项的一部分):
http://pic.test.net/images-small/001/002/123456.jpg
我必须将 /image-small/ 更改为 /image-big/。
URL 的部分内容是动态的(例如 /001/),所以我的想法是对这些部分使用某种通配符。这是我的静态版本 URL:
$("#resultlist-item").attr({"src":"http://pic.test.net/images-big/001/002/123456.jpg"});
它正在工作,但我不知道如何为动态 URL。
有什么想法吗?
非常感谢,
乔
试试这个:
<!-- SOME HTML AND ETC... -->
<div id="gallery">
<img src="http://pic.test.net/images-small/001/002/123456.jpg" />
<img src="http://pic.test.net/images-small/001/002/1234567.jpg" />
<img src="http://pic.test.net/images-small/001/002/1234568.jpg" />
</div>
<!-- SOME HTML AND ETC... -->
<script>
$(function(){
var $imagesContainer = $('#gallery');
$imagesContainer.find('img').each(function(){
var src = $(this).attr('src');
if(src.indexOf('images-small/')>-1) {
src = src.replace('images-small/', 'images-big/');
$(this).attr('src', src);
}
});
});
</script>
我正在尝试更改图像 src 的一部分以进行 A/B 测试,但在阅读了大量文章后,我变得越来越困惑。这是图像 URL(它是结果列表项的一部分):
http://pic.test.net/images-small/001/002/123456.jpg
我必须将 /image-small/ 更改为 /image-big/。
URL 的部分内容是动态的(例如 /001/),所以我的想法是对这些部分使用某种通配符。这是我的静态版本 URL:
$("#resultlist-item").attr({"src":"http://pic.test.net/images-big/001/002/123456.jpg"});
它正在工作,但我不知道如何为动态 URL。
有什么想法吗?
非常感谢, 乔
试试这个:
<!-- SOME HTML AND ETC... -->
<div id="gallery">
<img src="http://pic.test.net/images-small/001/002/123456.jpg" />
<img src="http://pic.test.net/images-small/001/002/1234567.jpg" />
<img src="http://pic.test.net/images-small/001/002/1234568.jpg" />
</div>
<!-- SOME HTML AND ETC... -->
<script>
$(function(){
var $imagesContainer = $('#gallery');
$imagesContainer.find('img').each(function(){
var src = $(this).attr('src');
if(src.indexOf('images-small/')>-1) {
src = src.replace('images-small/', 'images-big/');
$(this).attr('src', src);
}
});
});
</script>