现在的位置: 首页 > 综合 > 正文

jQuery中after的两种用法实例

2012年04月01日 ⁄ 综合 ⁄ 共 253字 ⁄ 字号 评论关闭

法一:
在每个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字符串。

抱歉!评论已关闭.