1、filter为过滤方法,过滤出想要选择的元素

描述:选中class类名为box的div并添加背景色红色

<body>
  <div class="box">div1</div>
  <div>div2</div>
</body>
<script type="text/javascript">
    $('div').filter('.box').css('background','red')
</script>

执行效果、:

jquery的filter、not、has方法

2、not方法和filter方法相反

<body>
  <div class="box">div1</div>
  <div>div2</div>
</body>
<script type="text/javascript">
    $('div').not('.box').css('background','red')
</script>

执行效果:

jquery的filter、not、has方法

3、has:包含

描述:查找包含span标签的div

<body>
  <div class="box"><span>div1</span></div>
  <div>div2</div>
</body>
<script type="text/javascript">
    $('div').has('span').css('background','red')
</script>

执行结果:

jquery的filter、not、has方法

相关文章:

  • 2021-10-27
  • 2022-03-04
  • 2021-10-25
  • 2022-12-23
  • 2022-12-23
  • 2022-02-12
  • 2021-09-09
猜你喜欢
  • 2021-09-05
  • 2021-11-07
  • 2021-08-22
  • 2022-03-01
  • 2022-02-03
相关资源
相似解决方案