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

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

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

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

此方法使用指定的HTML內(nèi)容或元素將匹配的元素內(nèi)容包裹起來。

語法一:

用指定的DOM元素去包裹匹配元素的內(nèi)容。

復(fù)制代碼 代碼如下:
$(selector).wrapInner(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;
   }
   p
   {
      width:150px;
      height:150px;
      border:1px solid red;
   }
</style>
<script type="text/javascript" src="mytest/jQuery/jquery-1.8.3.js"></script>
<script type="text/javascript">
    $(document).ready(function(){
        $("button").click(function(){
            $("div").wrapInner(document.createElement("p"));
        });
    });
</script>
</head>
<body>
    <div>這是div的內(nèi)容,將會(huì)被包裹</div>
    <div>這是div的內(nèi)容,將會(huì)被包裹</div>
    <button>用div包裹每個(gè)段落</button>
</body>
</html>

語法二:

用函數(shù)返回用于包裹匹配元素內(nèi)容的元素。

復(fù)制代碼 代碼如下:
$(selector).wrapInner(function)

參數(shù)列表:
參數(shù) 描述
function 返回用于包裹匹配元素內(nèi)容的函數(shù)。
實(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;
    }
    p
   {
        width:150px;
        height:150px;
        border:1px solid red;
    }
</style>
<script type="text/javascript" src="mytest/jQuery/jquery-1.8.3.js"></script>
<script type="text/javascript">
    $(document).ready(function(){
        $("button").click(function(){
           $("div").wrapInner(function(){
              return "<p></p>"
           });
        });
    });
</script>
</head>
<body>
    <div>這是div的內(nèi)容,將會(huì)被包裹</div>
    <div>這是div的內(nèi)容,將會(huì)被包裹</div>
    <button>用div包裹每個(gè)段落</button>
</body>
</html>

語法三:

用html標(biāo)記代碼包裹匹配元素的內(nèi)容。

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

參數(shù)列表:
參數(shù) 描述
html 用于包裹匹配元素內(nèi)容的html標(biāo)記代碼

實(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;
    }
    p
   {
        width:150px;
        height:150px;
        border:1px solid red;
    }
</style>
<script type="text/javascript" src="mytest/jQuery/jquery-1.8.3.js"></script>
<script type="text/javascript">
    $(document).ready(function(){
        $("button").click(function(){
            $("div").wrapInner("<p></p>");
        });
    });
</script>
</head>
<body>
    <div>這是div的內(nèi)容,將會(huì)被包裹</div>
    <div>這是div的內(nèi)容,將會(huì)被包裹</div>
    <button>用div包裹每個(gè)段落</button>
</body>
</html>

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

本文轉(zhuǎn)自:螞蟻部落http://www.softwhy.com/

相關(guān)文章

最新評論