个性化阅读
专注于IT技术分析

jQuery after()

点击下载

本文概述

jQuery after()方法用于在选定元素之后插入指定的内容。就像jQuery append()方法一样。

如果要在所选元素之前插入内容, 则应使用jQuery的before()方法。

句法:

$(selector).after(content, function(index))

jQuery after()方法的参数

参数 描述
Content 它是必填参数。它指定要插入的内容。其可能的值为:HTML元素jQuery对象DOM元素
Function (index) 它指定一个函数, 该函数返回用于插入的内容。 index:提供元素在集合中的索引位置。

jQuery after()方法的示例

让我们看一下jQuery after()方法的示例:

<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<script>
$(document).ready(function(){
    $("button").click(function(){
        $("p").after("<p><b>Hello srcmini02.com</b></p>");
    });
});
</script>
</head>
<body>
<button>Insert content after each p element</button>
<p>This is a tutorial website.</p>
<p>This is a training institute.</p>
</body>
</html>

立即测试

输出:

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

这是一个教程网站。

这是一家培训机构。

赞(0)
未经允许不得转载:srcmini » jQuery after()

评论 抢沙发

评论前必须登录!