jQuery 方法append与after

来源:互联网 发布:transmit mac 破解 编辑:程序博客网 时间:2024/04/30 15:56
<span style="font-family:Comic Sans MS;"><!doctype html><html> <head>  <meta charset="UTF-8">  <title>test</title>  <script type="text/javascript" src="scripts/jquery-1.8.2.min.js"></script>  <script>$(function(){$('#btn').click(function(){$('p').append('<span>this is append</span>');$('p').after('<span>this is after</span>');});});  </script> </head> <body><p>test</p><button id="btn">点击</button> </body></html></span>

测试之前DOM结构


测试之后DOM结构


由此可见

使用append()方法是将内容添加到<p>节点的里面

after()方法是将内容添加到<p>节点的后面

0 0