jQuery创建Dom元素
代码如下:
代码
1 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
2 "http://www.w3.org/TR/html4/loose.dtd">
3 <html>
4 <head>
5 <meta http-equiv="Content-Type" content="text/html; charset=gb2312">
6 <title>无标题文档</title>
7
8 <script src="jquery-1.4.2.min.js" type="text/javascript"></script>
9 <script language="javascript" type="text/javascript">
10 $(function(){
11 var oNewp = $("<p>我测试成功了</P>");
12 oNewp.insertAfter("#target");
13 });
14 </script>
15
16
17 </head>
18
19 <body>
20 <p id="target">
21 eeeeeeeeee
22 </p>
23 </body>
24 </html>
25
2 "http://www.w3.org/TR/html4/loose.dtd">
3 <html>
4 <head>
5 <meta http-equiv="Content-Type" content="text/html; charset=gb2312">
6 <title>无标题文档</title>
7
8 <script src="jquery-1.4.2.min.js" type="text/javascript"></script>
9 <script language="javascript" type="text/javascript">
10 $(function(){
11 var oNewp = $("<p>我测试成功了</P>");
12 oNewp.insertAfter("#target");
13 });
14 </script>
15
16
17 </head>
18
19 <body>
20 <p id="target">
21 eeeeeeeeee
22 </p>
23 </body>
24 </html>
25
需要注意的几点:
$(fuction(){
})此句就相当于window.onload函数,缺一不可。
总结:时刻要细心。