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

jQuery中wrapAll()方法用法實例

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

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

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

語法一:

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

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

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

實例:

復(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://m.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)記代碼包裹匹配的元素。

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

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

實例:

復(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://m.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)文章

最新評論

南陵县| 枣阳市| 兴城市| 利川市| 阿荣旗| 呼和浩特市| 阿瓦提县| 景德镇市| 东至县| 建始县| 信阳市| 博湖县| 靖江市| 深泽县| 辽中县| 桦甸市| 图木舒克市| 芦山县| 昌邑市| 桃源县| 贵港市| 鹤峰县| 兴城市| 绵竹市| 如皋市| 琼结县| 嘉定区| 宝清县| 连平县| 越西县| 宿迁市| 正阳县| 青冈县| 来宾市| 健康| 西平县| 广安市| 彰化市| 天峨县| 嵩明县| 辛集市|