📅  最后修改于: 2020-11-25 11:41:57             🧑  作者: Mango
jQuery prepend()方法用于将指定的内容插入所选元素的开头(作为第一个子元素)。它与jQuery append()方法相反。
如果要在所选元素的末尾插入内容,则应使用append方法。
句法:
$(selector).prepend(content,function(index,html))
Parameter | Description |
---|---|
Content | It is a mandatory parameter. It specifies the content which you want to insert. Its possible values are:
|
Function (index, html) | It is an optional parameter. It specifies a function that returns the content which is inserted.
|
让我们以一个示例来演示jQuery prepend()方法。
This is the first paragraph.
This is the second paragraph.
输出:
This is the first paragraph.
This is the second paragraph.
This is the first paragraph.
This is the second paragraph.
- Item no.1
- Item no.2
- Item no.3
输出:
This is the first paragraph.
This is the second paragraph.
prepend demo
javatpoint.com
Guys! Welcome to the best tutorial site.
输出:
Hello javatpoint.com
Hello Guys! Welcome to the best tutorial site.
在此,“ Hello”是前置文本。