jQuery 抄袭笔记(8) : Appendto和Append
11 Oct 2011通过append或者appendto方法可以向元素之后添加内容。
两者区别是:
1.
$(content).appendTo(selector)
2.
$(selector).append(content)
选择器和内容位置颠倒。
append() 能够使用函数来附加内容。
01 <!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Transitional//EN” “http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd”>
02 <html xmlns=“http://www.w3.org/1999/xhtml”>
03 </span>
04 <meta http-equiv=“Content-Type” content=“text/html; charset=gb2312″ />
05</span>AppendTo的用法</title>
06 <script type=“text/javascript” src=“jquery-1.1.3.pack.js”></script>
07 <script type=“text/javascript”>
08 $(document).ready(function(){
09 $(“#Lazy_btn1″).click(function(){
10 $(“<input type=’text’ name=’text1′ id=’text1′ value=’Lazynight’ >
”).appendTo(“#night”);
11 });
12 $(“#Lazy_btn2″).click(function(){
13 $(“#day”).append(“<input type=’text’ name=’text2′ id=’text2′ value=’Lazynight’ >
”);
14 });
15 });
16 </script>
17 </head>
18 </span>
19 <input type=“button” name=“btn1″ id=“Lazy_btn1″ value=“appendto”>
20 <input type=“button” name=“btn2″ id=“Lazy_btn2″ value=“append”>
21 <div name=“night” id=“night”>AppendTo组的变化</div>
22 <div name=“day” id=“day”>Append组的变化</div>
23 </body>
24 </html> </div> 下载源码 转载请注明:[于哲的博客][1] » [jQuery 抄袭笔记(8) : Appendto和Append][2] [1]: http://lazynight.me [2]: http://lazynight.me/439.html
02 <html xmlns=“http://www.w3.org/1999/xhtml”>
03 </span>
04 <meta http-equiv=“Content-Type” content=“text/html; charset=gb2312″ />
05
06 <script type=“text/javascript” src=“jquery-1.1.3.pack.js”></script>
07 <script type=“text/javascript”>
08 $(document).ready(function(){
09 $(“#Lazy_btn1″).click(function(){
10 $(“<input type=’text’ name=’text1′ id=’text1′ value=’Lazynight’ >
”).appendTo(“#night”);
11 });
12 $(“#Lazy_btn2″).click(function(){
13 $(“#day”).append(“<input type=’text’ name=’text2′ id=’text2′ value=’Lazynight’ >
”);
14 });
15 });
16 </script>
17 </head>
18 </span>
19 <input type=“button” name=“btn1″ id=“Lazy_btn1″ value=“appendto”>
20 <input type=“button” name=“btn2″ id=“Lazy_btn2″ value=“append”>
21 <div name=“night” id=“night”>AppendTo组的变化</div>
22 <div name=“day” id=“day”>Append组的变化</div>
23 </body>
24 </html> </div> 下载源码 转载请注明:[于哲的博客][1] » [jQuery 抄袭笔记(8) : Appendto和Append][2] [1]: http://lazynight.me [2]: http://lazynight.me/439.html