Home  >  Q&A  >  body text

detach()和remove()的区别?

var p = $("p:first").remove();
p.css('color','red').text('p1通过remove处理后,点击该元素,事件丢失')
$("body").append(p);

以上代码,p首先被移除掉了,自身元素p标签也应该将移除了,可是为什么p又重新设置样式及内容的时候却还是会是p标签呢

小白小白2832 days ago1050

reply all(2)I'll reply

  • 数据分析师

    数据分析师2017-09-30 22:57:43

    What is the difference between detach() and remove()? -PHP Chinese website Q&A-What is the difference between detach() and remove()? -PHP Chinese website Q&A

    Please watch and learn.

    reply
    0
  • 迷茫

    迷茫2016-12-19 17:30:19

    这个方法不会把匹配的元素从jQuery对象中删除,因而可以在将来再使用这些匹配的元素。但除了这个元素本身得以保留之外,其他的比如绑定的事件,附加的数据等都会被移除

    reply
    1
  • Cancelreply