亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定

jquery的remove()方法會將方法和數據移除,那么這個數據是指什么?

<html>

<head>

? ? <meta http-equiv="Content-type" content="text/html; charset=utf-8" />

? ? <style type="text/css">

? ? p{

? ? ? ? border: 1px solid red;

? ? }

? ? </style>

? ? <script src="http://libs.baidu.com/jquery/1.9.1/jquery.js"></script>

</head>

<body>

? ? <h3>給頁面2個p元素節點綁定點擊事件,點擊后彈出自己本身的節點內容</h3>

? ? <p id="p1">元素p1,同時綁定點擊事件</p>

? ? <p>元素p2,同時綁定點擊事件</p>

? ? <h3>通過點擊2個按鈕后觀察方法處理的區別</h3>

? ? <button>點擊通過remove處理元素p1</button>

? ? <button>點擊通過detach處理元素p2</button>

</body>

<script type="text/javascript">

? ? $("p").on("click",function(e){

? ? ? ? alert(e.target.innerHTML);

? ? });

? ? $("button:first").on("click",function(){

? ? ? ? var p = $("p:first").remove();

? ? ? ? alert(p.attr("id"));

? ? ? ? p.css("color","red").text("remove后事件也消失了");

? ? ? ? $("body").append(p);

? ? });

? ? $("button:eq(1)").on("click",function(){

? ? ? ? var p = $("p:eq(1)").detach();

? ? ? ? $("body").append(p);

? ? });

</script>

</script>

</html>

我給p加了id,我remove后將該對象的idalert了一下,還是可以出來,我比較好奇所說的數據是指什么?

正在回答

1 回答

這個問題很深,涉及到js內存處理機制。

0 回復 有任何疑惑可以回復我~

舉報

0/150
提交
取消

jquery的remove()方法會將方法和數據移除,那么這個數據是指什么?

我要回答 關注問題
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號