找回密碼
 立即註冊
搜索
熱搜: 活動 交友 discuz
查看: 372|回復: 0

比較 jQuery .empty(), .remove(), 與 .detach() 間的差異

[複製鏈接]

257

主題

38

回帖

1138

積分

管理員

積分
1138
發表於 2023-5-25 10:34:25 | 顯示全部樓層 |閱讀模式

在 jQuery 官網的文件中提到:

  • .empty(): This method removes not only child (and other descendant) elements, but also any text within the set of matched elements.

意即,移除你元素底下所有文字內容以及子元素

  • .remove(): Similar to .empty(), the .remove() method takes elements out of the DOM.

意即,除了.empty()原有行為外,指定的selector也會被移除

  • .detach(): The .detach() method is the same as .remove(), except that .detach() keeps all jQuery data associated with the removed elements.

意即,除了.remove()原有行為外,連原本綁定在裡面的事件都一併移除

您需要登錄後才可以回帖 登錄 | 立即註冊

本版積分規則

Archiver|手機版|小黑屋|DoIT 科技論壇

GMT+8, 2025-6-15 11:32 , Processed in 0.032762 second(s), 18 queries .

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

快速回復 返回頂部 返回列表