亚洲区国产区激情区无码区,国产成人mv视频在线观看,国产A毛片AAAAAA,亚洲精品国产首次亮相在线

jQuery prepend() 方法

jQuery HTML/CSS 方法

prepend()方法將指定的內(nèi)容插入每個(gè)選定元素的開頭(作為第一個(gè)子元素)。

要在所選元素的末尾插入內(nèi)容,請使用append()方法。

語法:

插入前置內(nèi)容:

$(selector).prepend(content)

使用函數(shù)添加內(nèi)容:

$(selector).prepend(function(index, html))

實(shí)例

在所有段落之前添加一些文本內(nèi)容:

$("button").click(function(){
  $("p").prepend("Hello world");
});
測試看看?/?

在所有段落前添加一些HTML:

$("button").click(function(){
  $("p").prepend("<b>Hello world</b>");
});
測試看看?/?

本示例使用document.createTextNode()創(chuàng)建文本節(jié)點(diǎn)并將其添加到所有<p>元素之前:

$("button").click(function(){
  $("p").prepend(document.createTextNode("Hello world"));
});
測試看看?/?

使用函數(shù)添加內(nèi)容:

$("button").click(function(){
  $("p").prepend(function(i){
return "<b>This p element has index " + i + "</b>";
  });
});
測試看看?/?

參數(shù)值

參數(shù)描述
content指定在每個(gè)選定元素的開頭插入的內(nèi)容(可以包含HTML標(biāo)記)

可能的值:

  • HTML元素

  • DOM元素

  • jQuery對象

function(index, html)指定一個(gè)函數(shù),該函數(shù)返回要插入的內(nèi)容
  • index-返回元素在集合中的索引位置

  • html-返回所選元素的當(dāng)前HTML

jQuery HTML/CSS 方法