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

.prepend()

.prepend( content ) 返回:jQuery

描述:將參數(shù)內(nèi)容插入到每個匹配元素的前面(元素內(nèi)部)。

  • version added: 1.0.prepend( content )

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

  • version added: 1.4.prepend( function(index, html) )

    function(index, html)一個返回HTML字符串的函數(shù),該字符串用來插入到匹配元素的末尾。 Receives the index position of the element in the set and the old HTML value of the element as arguments.

.prepend()方法將指定元素插入到匹配元素里面作為它的第一個子元素 (如果要作為最后一個子元素插入用.append()).

The .prepend().prependTo()實現(xiàn)同樣的功能,主要的不同時語法,插入的內(nèi)容和目標(biāo)的位置不同。 對于 .prepend(),函數(shù)前面的是插入的容器,參數(shù)是內(nèi)容。而.prependTo()剛好相反。

請看下面的HTML

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

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

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

結(jié)果如下:

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

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

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

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

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

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

例子:

Example: 在所有段落前面插入一些內(nèi)容。

<!DOCTYPE html>
<html>
<head>
  <style>p { background:yellow; }</style>
  <script src="http://code.jquery.com/jquery-latest.min.js"></script>
</head>
<body>
  <p>there friend!</p>

  <p>amigo!</p>
<script>$("p").prepend("<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'd say</p>
  <p>is what I said</p>
<script>$("p").prepend(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 was said.</p><b>Hello</b>
<script>$("p").prepend( $("b") );</script>

</body>
</html>

Demo:

jQuery 1.6 API 中文版腳本之家整理、修訂 (2011年6月)
涞源县| 沂水县| 香河县| 内黄县| 岫岩| 黑水县| 漯河市| 来宾市| 兴安盟| 漳浦县| 平罗县| 高密市| 天柱县| 繁峙县| 瑞金市| 湄潭县| 临城县| 东安县| 怀柔区| 石城县| 宝应县| 南丹县| 自贡市| 股票| 天门市| 金堂县| 阳城县| 平陆县| 五台县| 图木舒克市| 揭西县| 万山特区| 武清区| 九龙县| 宁津县| 阿鲁科尔沁旗| 皮山县| 丰都县| 平度市| 北票市| 调兵山市|