这里有一个简单的问题:
是否有比jquery更好的替代方法来删除下一个所有元素,包括($this)?
到目前为止,以下代码对我有效:$(this).nextAll().remove();$(this).remove();
这里有一个简单的问题:
是否有比jquery更好的替代方法来删除下一个所有元素,包括($this)?
到目前为止,以下代码对我有效:$(this).nextAll().remove();$(this).remove();
如果您想要链接您的调用,那么有几个选项可供选择,但这并不会对性能产生太大影响:
$(this).nextAll().remove().end().remove();
$(this).nextAll().add(this).remove();
$(this).nextAll().andSelf().remove();
.end()
:
结束当前链中最近的筛选操作,并将匹配的元素集返回到其先前的状态。
.add()
:
将元素添加到匹配元素集。
.andSelf()
:
将堆栈上前一次的元素集添加到当前集合中。
$(this).nextAll().add(this).remove();
更简洁。 - Joseph Marikle$(this).nextAll().andSelf().remove();
.nextAll()
方法,然后添加this
,最后在组合集合上调用.remove()
方法:$(this).nextAll().add(this).remove();
$(this).nextAll().remove().end().remove();
。 - Esailija