Javascript jquery更新锚定标记';基于查询字符串值的s图像src

Javascript jquery更新锚定标记';基于查询字符串值的s图像src,javascript,jquery,html,Javascript,Jquery,Html,如何替换每个元素上的图像src <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <div id="userShop"> <p class="shoppingbaskets"> <a href="RunFunction.jsp;jsessionid=123456789?shop=querty&ba

如何替换每个元素上的图像src

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id="userShop">
  <p class="shoppingbaskets">
    <a href="RunFunction.jsp;jsessionid=123456789?shop=querty&basket=empty"><img src="image/empty.png" title="empty" width="50" height="50"></a>
    <a href="RunFunction.jsp;jsessionid=123456789?shop=querty&basket=full"><img src="image/full.png" title="full" width="50" height="50"></a>
    <a href="RunFunction.jsp;jsessionid=123456789?shop=querty&basket=semi"><img src="image/semi.png" title="semi" width="50" height="50"></a>
    <a href="RunFunction.jsp;jsessionid=123456789?shop=querty&basket=abandoned"><img src="image/abandoned.png" title="abandoned" width="50" height="50"></a>
    <a href="RunFunction.jsp;jsessionid=123456789?shop=querty&basket=completed"><img src="image/completed.png" title="completed" width="50" height="50"></a>
  </p>
</div>

这是正确的方法吗?

实际上,有很多方法可以做到这一点

你只需要在谷歌上做一些研究就可以做到这一点,但是很好


let links=document.querySelectorAll('a');
log(“Src before:+$('#emptyImage').attr('Src'));
//迭代所有链接
links.forEach((el)=>{
//获取字符串中“空”的索引(如果存在)
if(el.search.indexOf('empty')!=-1){
//将src修改为新src
$(el.find('img').attr(“src”,“newDir/newImageEmpty.jpg”);
}
});
log(“Src-after:+$('#emptyImage').attr('Src'))


您尝试过什么?
var listStatus = [
    {
       'name': 'full',
       'image': 'http://www.faredelbene.net/img/icon_stumble.png'
    },
    // and some more for others

];

listStatus.forEach(function (item){
    $("#userShop a").each(function(link) {
  if (item.name.indexOf(
       new URL(this.href).searchParams.get("basket")
     ) !=-1) {
    $(this).find("img").attr({src: item.image});
  }
});
})