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

.before()

.before( content ) 返回:jQuery

描述: 根據(jù)參數(shù)設(shè)定在匹配元素的前面(外面)插入內(nèi)容

  • version added: 1.0.before( content )

    content一個元素,HTML字符串,或者jQuery對象,用來插入到匹配元素前面的內(nèi)容

  • version added: 1.4.before( function )

    function一個返回THML字符串的函數(shù),返回值作為用來被插入到陪陪元素前面的內(nèi)容。

.before().insertBefore()兩種方法實現(xiàn)同樣的功能。主要的區(qū)別是語法——內(nèi)容和目標(biāo)的位置。 對于 .before(),選擇表達式在函數(shù)前面,內(nèi)容作為參數(shù),而.insertBefore()剛好相反。

請看下面的HTML:

<div class="container">
  <h2>Greetings</h2>
  <div class="inner">Hello</div>
  <div class="inner">Goodbye</div>
</div>

我們可以創(chuàng)建內(nèi)容然后同時插入到好幾個元素里面:

$('.inner').before('<p>Test</p>');

每個新的inner <div>元素會得到新的內(nèi)容:

<div class="container">
  <h2>Greetings</h2>
  <p>Test</p>
  <div class="inner">Hello</div>
  <p>Test</p>
  <div class="inner">Goodbye</div>
</div>

我們也可以在頁面上選擇一個元素然后插在另一個元素前面:

$('.container').before($('h2'));

如果一個被選中的元素被這樣插入到另外一個地方,這是移動而不是復(fù)制:

<h2>Greetings</h2>
<div class="container">
  <div class="inner">Hello</div>
  <div class="inner">Goodbye</div>
</div>

如果有多個目標(biāo)元素,內(nèi)容將被復(fù)制然后按順序插入到每個目標(biāo)里面。

在jQuery 1.4中, .before().after()同樣對分離的DOM節(jié)點有效:

$("<div/>").before("<p></p>");

結(jié)果是一個jQuery set包含一個段落和一個 div。

例子:

Example: 在所有段落前插入一些HTML。

<!DOCTYPE html>
<html>
<head>
  <style>p { background:yellow; }</style>
  <script src="http://code.jquery.com/jquery-latest.min.js"></script>
</head>
<body>
  <p> is what I said...</p>
<script>$("p").before("<b>Hello</b>");</script>

</body>
</html>

Demo:

Example: 在所有段落前插入一個DOM元素。

<!DOCTYPE html>
<html>
<head>
  <style>p { background:yellow; }</style>
  <script src="http://code.jquery.com/jquery-latest.min.js"></script>
</head>
<body>
  <p> is what I said...</p>
<script>$("p").before( document.createTextNode("Hello") );</script>

</body>
</html>

Demo:

Example: 在所有段落前插入一個jQuery對象(類似于一個DOM元素數(shù)組)。

<!DOCTYPE html>
<html>
<head>
  <style>p { background:yellow; }</style>
  <script src="http://code.jquery.com/jquery-latest.min.js"></script>
</head>
<body>
  <p> is what I said...</p><b>Hello</b>
<script>$("p").before( $("b") );</script>

</body>
</html>

Demo:

jQuery 1.6 API 中文版腳本之家整理、修訂 (2011年6月)
许昌县| 介休市| 攀枝花市| 延吉市| 上蔡县| 通化县| 玉门市| 霍山县| 涞水县| 东至县| 舞阳县| 新津县| 集安市| 滁州市| 淳化县| 额尔古纳市| 石泉县| 陆川县| 安国市| 乌鲁木齐县| 阆中市| 老河口市| 饶平县| 遂宁市| 三门峡市| 东乡县| 松阳县| 巢湖市| 疏勒县| 明光市| 三穗县| 鄱阳县| 三原县| 诸暨市| 宁城县| 谷城县| 报价| 旬邑县| 恩施市| 清河县| 桐梓县|