gpt4 book ai didi

javascript - jQuery detach() vs remove() vs hide()

转载 作者:可可西里 更新时间:2023-11-01 02:06:21 27 4
gpt4 key购买 nike

<分区>

我在我的页面中使用了 highcharts。有点重。

当用户点击一个按钮时,它会动态加载图表,当用户点击关闭按钮时,它会删除/隐藏图表。

我想知道哪个更好。

  1. 在用户点击时隐藏图表?它会减慢页面其余部分的速度吗(因为存在繁重的 javascript 和处理程序?)或者,

  2. remove() 它,使页面更轻(但是在这里,当用户再次点击按钮时,我需要再次加载图表)或者,

  3. 使用 detach() ,这样在重新加载 highcharts 时,它工作得更快比 remove() (但它不会像 jQuery 一样使页面更重处理程序一直在场?)

我从 jQuery 文档中了解到,

.remove()

the .remove() method takes elements out of the DOM. Use .remove() when you want to remove the element itself, as well as everything inside it. In addition to the elements themselves, all bound events and jQuery data associated with the elements are removed.

.detach()

The .detach() method is the same as .remove(), except that .detach() keeps all jQuery data associated with the removed elements. This method is useful when removed elements are to be reinserted into the DOM at a later time.

.hide()

The matched elements will be hidden immediately, with no animation. This is roughly equivalent to calling .css('display', 'none')

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com