我有一个图像列表,具有这种结构:
<div class="product">
<div class="p" itemscope="" itemtype="https://schema.org/Product">
<a href="/head/" class="p-image">
<img src="https://cdn.myshoptet.com/usr/www.nebenebo.cz/user/shop/detail/348.jpg?5a1af136" data-src="https://cdn.myshoptet.com/usr/www.nebenebo.cz/user/shop/detail/348.jpg?5a1af136" alt="69Jirka Macek Head">
<meta itemprop="image" content="https://cdn.myshoptet.com/usr/www.nebenebo.cz/user/shop/big/348.jpg?5a1af136">
</a>
</div>
</div>
使用JS,我需要在特定类的所有img上将路径文件夹从"detail/"
更改为"big/"
。
我尝试了这个,但它不起作用:
$('.product a img').attr('src').replace('detail', 'big');
答案 0 :(得分:0)
//if you want to change the "detail" to "big" for all images,
$('.product a img').each(function(){
$(this).attr('src', $(this).attr('src').replace('detail', 'big'));
})
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="product">
<div class="p" itemscope="" itemtype="https://schema.org/Product">
<a href="/head/" class="p-image">
<img src="https://cdn.myshoptet.com/usr/www.nebenebo.cz/user/shop/detail/348.jpg?5a1af136" data-src="https://cdn.myshoptet.com/usr/www.nebenebo.cz/user/shop/detail/348.jpg?5a1af136" alt="69Jirka Macek Head">
<meta itemprop="image" content="https://cdn.myshoptet.com/usr/www.nebenebo.cz/user/shop/big/348.jpg?5a1af136">
</a>
</div>
</div>