有条件地删除jQuery上的表格行 [英] Conditional remove table row on jQuery

查看:76
本文介绍了有条件地删除jQuery上的表格行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一些桌子

  <table>
  <tr class="trclass">
  <td class ="tdc">
  <img src="/images/products/nophoto_s.jpg">
  </td>
  </tr>
  </table>

如果img src标签不包含nophoto_s.jpg,如何删除表行?

How to remove table row if img src tag not include nophoto_s.jpg ?

推荐答案

filter可以采用允许您指定所需条件的功能.将其与find一起使用,可抓取具有nophoto_s.jpg作为src图像的所有表行,然后将其删除.

filter can take a function allowing you to specify any condition you'd like. Use this, with find, to grab all table rows that have an image with nophoto_s.jpg as the src, then remove them.

$("tr").filter(function() {
    return $(this).find("img[src*='nophoto_s.jpg']").length > 0;
}).remove();

这是小提琴

这篇关于有条件地删除jQuery上的表格行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆