after() 方法在被选元素后插入指定的内容
法一:
在每个p元素后插入内容:
$("button").click(function(){
$("p").after("
});
法二:
$("button").click(function(){
$("p").after(function(n){
return "
});
});
after中函数必须返回一个html字符串。
在每个p元素后插入内容:
复制代码 代码如下:
$("button").click(function(){
$("p").after("
Hello world!
");});
法二:
复制代码 代码如下:
$("button").click(function(){
$("p").after(function(n){
return "
The p element above has index " + n + "
";});
});
after中函数必须返回一个html字符串。
以上就是jQuery中after的两种用法实例的详细内容,更多请关注0133技术站其它相关文章!