jquery根据查询字符串删除标签

tee*_*tee 2 html javascript jquery

我在div中的ap标签内有一个图像列表

我如何使用jQuery删除a,如果标签basket=等于其中之一empty,semi,abandoned

<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>
Run Code Online (Sandbox Code Playgroud)

mpl*_*jan 5

URL.searchParams在这里很有用

$("#userShop a").each(function(link) {
  if (["empty","semi","abandoned"].indexOf(
       new URL(this.href).searchParams.get("basket")
     ) !=-1) {
    $(this).remove();
  }
});
Run Code Online (Sandbox Code Playgroud)
<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>
Run Code Online (Sandbox Code Playgroud)