PRepend()方法定义和用法:
此方法可以将指定元素插入匹配元素内部的开头。
prepend()方法的作用和prependTo()是相同的,但是在语法上是有差别的,虽然在语法形式上看起来是一样的。
语法结构:
$(selector).prepend(content)
参数列表:
参数
描述
content
指定被插入的内容,content的可能的值:
1.HTML 代码 - 比如 ("<div></div>")。
2.已存在的元素 - 比如 ($(".div1"))。
3.function(index)函数 - 定义返回包围元素的函数,index参数接收选择器的索引位置。
selector
要被插入内容的匹配元素。
实例代码:
<!DOCTYPE html><html><head><metacharset="utf-8"><metaname="author"content="http://www.51texiao.cn/"/><title>蚂蚁部落</title><styletype="text/CSS">div{height:200px;width:200px;border:1px solid green;}</style><scripttype="text/javascript"src="mytest/jQuery/jquery-1.8.3.js"></script><scripttype="text/Javascript">$(document).ready(function(){
$("button").click(function(){
$("div").prepend("被加添的内容");
})
})</script></head><body><div>前面要添加内容:</div><button>点击查看效果</button></body></html>
原文地址是:http://www.51texiao.cn/jqueryjiaocheng/2015/0613/4050.html
最为原始地址是:http://www.softwhy.com/forum.php?mod=viewthread&tid=5284