Jquery next 找不到下一个 div?

2023-11-27

我有这个 HTML 结构

<img  width="25" height="25" src=/data/apple_logo.jpg alt=Chocolate />      
  <input class="cake_checkboxes" style="vertical-align: bottom;"  type="checkbox" name="option[232][]" value="23" id="option-value-23" />
  <label for="option-value-23"> Chocolate</label>
  <br />
<div style='display:none;' class="quantity">
......

If i do

$('.cake_checkboxes:first').next('div')

or

$('.cake_checkboxes:first').next('.quantity')

我得到一个空值返回,但如果我这样做

$('.cake_checkboxes:first').next().next().next()

我得到了我需要的 div ...关于哪里出了问题或者是否有办法像 jquery 一样向下遍历的任何想法closest方法向上遍历


next()仅当与选择器匹配时才返回 DOM 中的下一个元素,否则返回空对象。所以你唯一可以搜索的就是使用next() is the <label>。使用这个代替:

$('.cake_checkboxes:first').nextAll('.quantity').first()

jQuery 文档:nextAll()

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

Jquery next 找不到下一个 div? 的相关文章

随机推荐