jQuery中after的用法

来源:岁月联盟 编辑:exp 时间:2012-02-14

after() 方法在被选元素后插入指定的内容。

 

法一:

在每个p元素后插入内容:

$("button").click(function(){
      $("p").after("<p>Hello world!</p>");
});

 

 

法二:

 $("button").click(function(){
    $("p").after(function(n){
            return "<p>The p element above has index " + n + "</p>";
    });

});

 

after中函数必须返回一个html字符串。

 

摘自 徐越的专栏