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

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

 更新時(shí)間:2015年01月16日 14:20:34   投稿:shichen2014  
這篇文章主要介紹了jQuery中wrapAll()方法用法,實(shí)例分析了wrapAll()方法的功能、定義及匹配元素的使用技巧,需要的朋友可以參考下

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

此方法將所有匹配的元素用單個(gè)元素包裹起來。
此方法與wrap()方法雖然功能類似,但是有著很大區(qū)別。wrap()方法會(huì)把每一個(gè)匹配的元素都匹配一次。

語法一:

用指定的DOM元素去包裹匹配元素。

復(fù)制代碼 代碼如下:
$(selector).wrapAll(elem)

參數(shù)列表:
參數(shù) 描述
elem 用于包裹目標(biāo)的DOM元素。

實(shí)例:

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

<!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.dbjr.com.cn/" />
<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>我是個(gè)段落</p>
    <p>我是個(gè)段落</p>
    <div id="content"></div>
    <button>用div包裹每個(gè)段落</button>
</body>
</html>

語法二:

用html標(biāo)記代碼包裹匹配的元素。

復(fù)制代碼 代碼如下:
$(selector).wrapAll(html)

參數(shù)列表:
參數(shù) 描述
elem 用于包裹目標(biāo)的DOM元素。

實(shí)例:

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

<!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.dbjr.com.cn/" />
<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>這是個(gè)段落</p>
   <p>這是個(gè)段落</p>
   <button>用div包裹每個(gè)段落</button>
</body>
</html>

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

相關(guān)文章

最新評論