国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁(yè) > 編程 > JavaScript > 正文

jQuery的remove()方法使用詳解

2019-11-20 11:52:23
字體:
來(lái)源:轉(zhuǎn)載
供稿:網(wǎng)友

remove()方法的定義和用法:

此方法將會(huì)從DOM中刪除所有匹配的元素。

說(shuō)明:remove()方法不會(huì)把匹配的元素從jQuery對(duì)象中刪除,因而可以在將來(lái)再使用這些匹配的元素,不過(guò)除了這個(gè)元素本身得以保留之外,其他的比如綁定的事件,附加的數(shù)據(jù)等都會(huì)被移除。

語(yǔ)法結(jié)構(gòu):

$(selector).remove(expr)

參數(shù)列表:

參數(shù) 描述
expr 可選。用于篩選元素的jQuery表達(dá)式

實(shí)例代碼:

<!DOCTYPE html><html><head><meta charset="utf-8"><script type="text/javascript" src="mytest/jQuery/jquery-1.8.3.js"></script><script type="text/javascript"> $(document).ready(function(){ $("button").click(function(){  $("div").remove("#first"); })})</script> </head><body><div id="first">我是第一</div><div id="second">我是第二</div><button>點(diǎn)擊</button></body></html>

以下代碼能夠刪除div集合中id為first的div。

<!DOCTYPE html><html><head><meta charset="utf-8"><script type="text/javascript" src="mytest/jQuery/jquery-1.8.3.js"></script><script type="text/javascript"> $(document).ready(function(){ $("#btd").click(function(){  $("div").remove(); })})</script> </head><body><div id="first">我是第一</div><div id="second">我是第二</div><button id="btd">點(diǎn)擊刪除第一個(gè)div</button></body></html>

如果省略參數(shù),那就是刪除所有匹配的元素。

<!DOCTYPE html><html><head><meta charset="utf-8"><style type="text/css">div{ width:200px; height:200px; border:5px solid green;}</style><script type="text/javascript" src="mytest/jQuery/jquery-1.8.3.js"></script><script type="text/javascript"> $(document).ready(function(){ $("#btd").click(function(){  var a=$("div");  a.remove("#first");  $("#btn").click(function(){   alert(a.length);  }) })})</script> </head><body><div id="first">我是第一</div><div id="second">我是第二</div><button id="btd">刪除第一個(gè)div</button><button id="btn">查看刪除操作后div的數(shù)量</button></body></html>

remove()已經(jīng)將DOM中的匹配元素刪除,但是并沒(méi)有將它從jquery對(duì)象中刪除。

jquery使用remove()方法刪除指定class子元素的方法

<!DOCTYPE html><html><head><script src="js/jquery.min.js"></script><script>$(document).ready(function(){ $("button").click(function(){ $("p").remove(".italic"); });});</script></head><body><p>This is a paragraph in the div.</p><p class="italic"><i>This is another paragraph in the div.</i></p><p class="italic"><i>This is another paragraph in the div.</i></p><button>Remove all p elements with class="italic"</button></body></html>

看到這段代碼之后,我想不用我過(guò)多的解釋了。大家就明白了吧,很有意思的方法。

發(fā)表評(píng)論 共有條評(píng)論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 磴口县| 遂川县| 延寿县| 台东市| 木兰县| 普兰店市| 河池市| 碌曲县| 铁力市| 简阳市| 新巴尔虎右旗| 额尔古纳市| 大宁县| 正定县| 喀什市| 临朐县| 张掖市| 拉萨市| 昭觉县| 嘉善县| 大同市| 蓬莱市| 长岛县| 石嘴山市| 大荔县| 哈尔滨市| 通河县| 肥西县| 潜江市| 隆安县| 正镶白旗| 鲁甸县| 武冈市| 广汉市| 宝坻区| 成安县| 宿州市| 陈巴尔虎旗| 开平市| 弋阳县| 上思县|