jQuery after() 方法
实例
在每个 <p> 元素后插入内容:
<!DOCTYPE html><html><head><script src="https://libs.baidu.com/jquery/2.1.4/jquery.min.js"></script><script>$(document).ready(function(){$("button").click(function(){$("p").after("<p>Hello world!</p>");});});</script></head><body><button>在每个 p 元素后插入内容</button><p>这是一个段落</p><p>这是另一个段落</p></body></html>
定义与用法
after() 方法在选定元素之后插入指定的内容。
提示:要在选定元素之前插入内容,请使用 before() 方法。
语法
$(selector).after(content,function(index))
| 参数 | 描述 |
|---|---|
| content | 必填。指定要插入的内容(可以包含 HTML 标记) 值可以为:
|
| function(index) | 指定返回要插入的内容的函数
|