首页 > 语言 > JavaScript > 正文

jQuery中after的两种用法实例

2024-05-06 15:48:30
字体:
来源:转载
供稿:网友
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字符串。
发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表

图片精选