jQuery中wrapAll()方法用法實(shí)例
本文實(shí)例講述了jQuery中wrapAll()方法用法。分享給大家供大家參考。具體分析如下:
此方法將所有匹配的元素用單個元素包裹起來。
此方法與wrap()方法雖然功能類似,但是有著很大區(qū)別。wrap()方法會把每一個匹配的元素都匹配一次。
語法一:
用指定的DOM元素去包裹匹配元素。
參數(shù)列表:
實(shí)例:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="author" content="http://www.fzitv.net/" />
<head>
<title>腳本之家</title>
<style type="text/css">
div
{
width:200px;
height:200px;
border:1px solid blue;
margin-top:10px;
}
</style>
<script type="text/javascript" src="mytest/jQuery/jquery-1.8.3.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$("button").click(function(){
$("p").wrapAll(document.getElementById("content"));
});
});
</script>
</head>
<body>
<p>我是個段落</p>
<p>我是個段落</p>
<div id="content"></div>
<button>用div包裹每個段落</button>
</body>
</html>
語法二:
用html標(biāo)記代碼包裹匹配的元素。
參數(shù)列表:
實(shí)例:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="author" content="http://www.fzitv.net/" />
<head>
<title>腳本之家</title>
<style type="text/css">
.content
{
width:200px;
height:200px;
border:1px solid blue;
}
</style>
<script type="text/javascript" src="mytest/jQuery/jquery-1.8.3.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$("button").click(function(){
$("p").wrapAll("<div class='content'></div>");
});
});
</script>
</head>
<body>
<p>這是個段落</p>
<p>這是個段落</p>
<button>用div包裹每個段落</button>
</body>
</html>
希望本文所述對大家的jQuery程序設(shè)計有所幫助。
相關(guān)文章
JQuery中DOM加載與事件執(zhí)行實(shí)例分析
這篇文章主要介紹了JQuery中DOM加載與事件執(zhí)行,實(shí)例分析了jQuery中DOM加載及事件執(zhí)行的原理與實(shí)現(xiàn)方法,并補(bǔ)充說明了windows.onload方法和$(document).ready()方法的區(qū)別,需要的朋友可以參考下2015-06-06
jQuery 順便學(xué)習(xí)下CSS選擇器 奇偶匹配nth-child(even)
今天學(xué)習(xí)jQuery,看到nth-child(even)用法,特意找了下這個選擇器的用法,在CSS3標(biāo)準(zhǔn)中,用法很強(qiáng)大。2010-05-05
當(dāng)鼠標(biāo)移動時出現(xiàn)特效的JQuery代碼
當(dāng)鼠標(biāo)移動時出現(xiàn)特效,在某些情況下還是比較實(shí)現(xiàn)的,下面為大家介紹下通過JQuery是如何實(shí)現(xiàn)的,具體如下,感興趣的朋友可以參考下2013-11-11
jQuery EasyUI API 中文文檔 - Form表單
jQuery EasyUI API 中文文檔 - Form表單,使用jQuery EasyUI的朋友可以參考下。2011-10-10

