欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

jQuery中remove()方法用法實(shí)例

 更新時間:2014年12月25日 15:58:20   投稿:shichen2014  
這篇文章主要介紹了jQuery中remove()方法用法,以三個不同的實(shí)例形式分別演示了remove()方法刪除元素的使用技巧,具有一定的參考借鑒價值,需要的朋友可以參考下

本文實(shí)例講述了jQuery中remove()方法用法。分享給大家供大家參考。具體分析如下:

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

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

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

復(fù)制代碼 代碼如下:
$(selector).remove(expr)

參數(shù)列表:

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

實(shí)例一:

復(fù)制代碼 代碼如下:

<!DOCTYPE html>
<html>
<head>
<meta charset=" utf-8">
<meta name="author" content="http://www.dbjr.com.cn/" />
<title>remove()函數(shù)-腳本之家</title>
<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。

實(shí)例二:

復(fù)制代碼 代碼如下:

<!DOCTYPE html>
<html>
<head>
<meta charset=" utf-8">
<meta name="author" content="http://www.dbjr.com.cn/" />
<title>remove()函數(shù)-腳本之家</title>
<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)擊刪除第一個div</button>
</body>
</html>

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

實(shí)例三:

復(fù)制代碼 代碼如下:

<!DOCTYPE html>
<html>
<head>
<meta charset=" utf-8">
<meta name="author" content="http://www.dbjr.com.cn/" />
<title>remove()函數(shù)-腳本之家</title>
<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">刪除第一個div</button><button id="btn">查看刪除操作后div的數(shù)量</button>
</body>
</html>

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

希望本文所述對大家的jQuery程序設(shè)計有所幫助。

相關(guān)文章

最新評論