jQuery中after的两种用法实例

2019-12-24,,,,

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

您可能感兴趣的文章:

  • jQuery中append、insertBefore、after与insertAfter方法注意事项
  • jQuery中before()方法用法实例
  • jQuery 追加元素的方法如append、prepend、before
  • jQuery使用after()方法在元素后面添加多项内容的方法
  • jQuery中after()方法用法实例
  • jQuery使用before()和after()在元素前后添加内容的方法

《jQuery中after的两种用法实例.doc》

下载本文的Word格式文档,以方便收藏与打印。