jQuery文档操作方法对比
1 <!DOCTYPE html> 2 <html> 3 <head> 4 <meta charset="UTF-8"> 5 <title>Insert title here</title> 6 <script type="text/javascript" src="js/jquery-3.3.1.js"></script> 7 <script type="text/javascript"> 8 $(document).ready(function(){ 9 $("div").after("<p>我是after方法插入过来的</p>"); 10 $("div").append("<p>我是append方法插入过来的</p>"); 11 $("div").before("<p>我是before方法插入过来的</p>"); 12 $("div").prepend("<p>我是prepend方法插入过来的</p>"); 13 $("div").append("<p>我是append方法第二次插入过来的</p>"); 14 $("div").after("<p>我是after方法第二次插入过来的</p>"); 15 }) 16 </script> 17 </head> 18 <body> 19 <div style="height:200px; width:200px; border:2px solid;"></div> 20 </body> 21 </html>
调试

备注
after()和before()方法只能在标签后面插入;prepend()和apppend()方法可以在标签内插入
前者只能在固定的位置(即永远都是在标签后一个位置插入);后者可以连续加入(即依次累加在标签内)
jQuery使用时src的写法
本地:若jQuery.js文件与HTML文件在同一个文件夹中,src="jQuery.js"
若jQuery.js文件所在的文件夹与HTML文件在同一个目录,src="文件夹/jQuery.js"
若jQuery.js文件所在的文件夹与HTML文件所在的文件夹为同一个目录,src="../文件夹/jQuery.js"
也可以直接写入jQuery.js文件的详细路径
非本地:
从 Google 或 Microsoft 加载 CDN jQuery 核心文件
Microsoft的jQuery库
src="http://ajax.microsoft.com/ajax/jquery/jquery-1.4.min.js"
Google的jQuery库
src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.0/jquery.min.js"
2197

被折叠的 条评论
为什么被折叠?



