首页 > 语言 > JavaScript > 正文

jQuery中after的两种用法实例

2024-05-06 14:37:59
字体:
来源:转载
供稿:网友
法一:
在每个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字符串。
发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表

图片精选