最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

jQuery 刪除或是清空某個HTML元素示例

 更新時間:2014年08月04日 10:36:41   投稿:whsnow  
刪除HTML元素可以使用remove及empty,下面有關(guān)這兩個方法的使用將以示例的方式為大家介紹下

jQuery使用下面兩個方法來刪除或是清空某個HTML元素。

remove() – 刪除指定的元素(包括其子元素)
empty() – 清空指定元素的子元素

例如:

<!DOCTYPE html> 
<html> 
<head> 
<meta charset="utf-8"> 
<title>JQuery Demo</title> 
<script src="scripts/jquery-1.9.1.js"></script> 
<script> 
$(document).ready(function () { 
$("button").click(function () { 
$("#div1").remove(); 
}); 
}); 
</script> 
</head> 
<body> 

<div id="div1" style="height: 100px; width: 300px; 
border: 1px solid black; background-color: yellow;"> 
This is some text in the div. 
<p>This is a paragraph in the div.</p> 
<p>This is another paragraph in the div.</p> 

</div> 
<br> 
<button>Remove div element</button> 

</body> 
</html>
empty:
<!DOCTYPE html> 
<html> 
<head> 
<meta charset="utf-8"> 
<title>JQuery Demo</title> 
<script src="scripts/jquery-1.9.1.js"></script> 
<script> 
$(document).ready(function () { 
$("button").click(function () { 
$("#div1").empty(); 
}); 
}); 
</script> 
</head> 
<body> 

<div id="div1" style="height: 100px; width: 300px; 
border: 1px solid black; background-color: yellow;"> 
This is some text in the div. 
<p>This is a paragraph in the div.</p> 
<p>This is another paragraph in the div.</p> 

</div> 
<br> 
<button>Empty the div element</button> 

</body> 
</html>

jQuery的remove()方法也支持一個參數(shù),可以用于過濾一些需要刪除的HTML元素。這個參數(shù)可以為任何有效的jQuery selector.
比如下面代碼只刪除class=”italic”的<p>元素:

$("p").remove(".italic");

相關(guān)文章

最新評論

鄢陵县| 曲阜市| 崇礼县| 团风县| 新竹市| 邵阳县| 蓬安县| 克什克腾旗| 施甸县| 霞浦县| 长岭县| 伽师县| 宜兴市| 磐石市| 金门县| 雷山县| 右玉县| 清水河县| 简阳市| 兴和县| 平邑县| 德兴市| 鄂托克前旗| 承德县| 军事| 长乐市| 大悟县| 涪陵区| 平潭县| 汾西县| 六盘水市| 忻城县| 双流县| 湘潭县| 铅山县| 历史| 永新县| 察隅县| 新巴尔虎右旗| 安阳市| 岢岚县|