📜  jQuery prepend()

📅  最后修改于: 2020-11-25 11:41:57             🧑  作者: Mango

jQuery prepend()

jQuery prepend()方法用于将指定的内容插入所选元素的开头(作为第一个子元素)。它与jQuery append()方法相反。

如果要在所选元素的末尾插入内容,则应使用append方法。

句法:

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

jQuery prepend()方法的参数

Parameter Description
Content It is a mandatory parameter. It specifies the content which you want to insert. Its possible values are:
  • HTML elements
  • jQuery objects
  • DOM elements
Function (index, html) It is an optional parameter. It specifies a function that returns the content which is inserted.
  • Index:It is used to provide the index position of the element in the set.
  • Html: : It provides the current HTML of the selected element.

jQuery prepend()方法的示例

让我们以一个示例来演示jQuery prepend()方法。

  
  
  
  
  
  
  

This is the first paragraph.

This is the second paragraph.

输出:

This is the first paragraph.

This is the second paragraph.

jQuery prepend()示例2








This is the first paragraph.

This is the second paragraph.

  1. Item no.1
  2. Item no.2
  3. Item no.3

输出:

This is the first paragraph.

This is the second paragraph.

  1. Item no.1
  2. Item no.2
  3. Item no.3

jQuery prepend()示例3




  
  prepend demo
  
  


 

javatpoint.com

Guys! Welcome to the best tutorial site.

输出:

Hello javatpoint.com

Hello Guys! Welcome to the best tutorial site.

在此,“ Hello”是前置文本。