日韩av黄I国产麻豆传媒I国产91av视频在线观看I日韩一区二区三区在线看I美女国产在线I麻豆视频国产在线观看I成人黄色短片

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 >

转:jQ函数after、append、appendTo的区别

發(fā)布時(shí)間:2025/5/22 39 豆豆
生活随笔 收集整理的這篇文章主要介紹了 转:jQ函数after、append、appendTo的区别 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

1、after函數(shù)
定義和用法:
after() 方法在被選元素后插入指定的內(nèi)容。參考:http://keleyi.com/a/bjac/cfyxd60g.htm

語法:
$(selector).after(content)

實(shí)例效果體驗(yàn):http://keleyi.com/keleyi/phtml/jquery/13.htm

實(shí)例代碼:

<html> <head> <title>jquery的after函數(shù)實(shí)例-柯樂義</title><base target="_blank" /> <script type="text/javascript" src="http://keleyi.com/keleyi/pmedia/jquery/jquery-1.10.2.min.js"></script> <style> .yuanlai_keleyi_com{border:1px solid black;padding:5px} .a_keleyi_com{color:Blue;} a{color:Blue} </style> </head> <body> <br /> <span class="yuanlai_keleyi_com">柯樂義,這是span里的內(nèi)容,keleyi.com。<a href="http://keleyi.com/a/bjac/2oncd079.htm">原文</a></span> <br /> <br /><button id="after_keleyi_com">after函數(shù)</button><br /><br /> <a href="http://keleyi.com/keleyi/phtml/jquery/13a.htm">append函數(shù)</a> <a href="http://keleyi.com/keleyi/phtml/jquery/13b.htm">appendTo函數(shù)</a> <script type="text/javascript"> $("#after_ke"+"leyi_com").click(function () { $("span").after('<a href="http://keley'+'i.com" class="a_kel'+'eyi_com">這是after函數(shù)加上去的內(nèi)容</a>') }) </script> </body> </html>

結(jié)果如下:

<span class="yuanlai_keleyi_com">柯樂義,這是span里的內(nèi)容,keleyi.com。<a href="http://keleyi.com/a/bjac/2oncd079.htm">原文</a></span><a href="http://keleyi.com" class="a_keleyi_com">這是after函數(shù)加上去的內(nèi)容</a>

即:span標(biāo)簽后面多了一個(gè)a標(biāo)簽

2、append函數(shù)

定義和用法:
append() 方法在被選元素的結(jié)尾(仍然在內(nèi)部)插入指定內(nèi)容。參考:http://keleyi.com/a/bjac/0vpch15n.htm

語法:
$(selector).append(content)

實(shí)例效果體驗(yàn):http://keleyi.com/keleyi/phtml/jquery/13a.htm

實(shí)例代碼:

<html> <head> <title>jquery的append函數(shù)實(shí)例-柯樂義</title><base target="_blank" /> <script type="text/javascript" src="http://keleyi.com/keleyi/pmedia/jquery/jquery-1.10.2.min.js"></script> <style> .yuanlai_keleyi_com{border:1px solid black;padding:5px} .a_keleyi_com{color:Blue;} a{color:Blue} </style> </head> <body> <br /> <span class="yuanlai_keleyi_com">柯樂義,這是span里的內(nèi)容,keleyi.com。<a href="http://keleyi.com/a/bjac/2oncd079.htm">原文</a>。</span> <br /> <br /><button id="after_keleyi_com">append函數(shù)</button><br /><br /> <a href="http://keleyi.com/keleyi/phtml/jquery/13.htm">after函數(shù)</a> <a href="http://keleyi.com/keleyi/phtml/jquery/13b.htm">appendTo函數(shù)</a> <script type="text/javascript"> $("#after_ke" + "leyi_com").click(function () { $(".yuanlai_ke"+"leyi_com").append('<a href="http://keley' + 'i.com" class="a_kel' + 'eyi_com">這是append函數(shù)加上去的內(nèi)容</a>') }) </script> </body> </html>

結(jié)果如下:

<span class="yuanlai_keleyi_com">柯樂義,這是span里的內(nèi)容,keleyi.com。<a href="http://keleyi.com/a/bjac/2oncd079.htm">原文</a><a href="http://keleyi.com" class="a_keleyi_com">這是after函數(shù)加上去的內(nèi)容</a></span>

即:span標(biāo)簽里面多了一個(gè)a標(biāo)簽

3、appendTo函數(shù)
定義和用法:
appendTo() 方法在被選元素的結(jié)尾(仍然在內(nèi)部)插入指定內(nèi)容。參考:http://keleyi.com/a/bjac/opnw2awa.htm

語法:
$(content).appendTo(selector)

實(shí)例效果體驗(yàn):http://keleyi.com/keleyi/phtml/jquery/13b.htm

實(shí)例代碼:

<html> <head> <title>jquery的appendTo函數(shù)實(shí)例-柯樂義</title><base target="_blank" /> <script type="text/javascript" src="http://keleyi.com/keleyi/pmedia/jquery/jquery-1.10.2.min.js"></script> <style> .yuanlai_keleyi_com{border:1px solid black;padding:5px} a{color:Blue} .a_keleyi_com{color:Blue;} </style> </head> <body> <br /> <span class="yuanlai_keleyi_com">柯樂義,這是span里的內(nèi)容,keleyi.com。<a href="http://keleyi.com/a/bjac/2oncd079.htm">原文</a>。</span> <br /> <br /><button id="after_keleyi_com">appendTo函數(shù)</button> <br /><br /> <a href="http://keleyi.com/keleyi/phtml/jquery/13a.htm">append函數(shù)</a> <a href="http://keleyi.com/keleyi/phtml/jquery/13.htm">after函數(shù)</a> <script type="text/javascript"> $("#after_ke" + "leyi_com").click(function () { $('<a href="http://keley' + 'i.com" class="a_kel' + 'eyi_com">這是appendTo函數(shù)加上去的內(nèi)容</a>').appendTo(".yuanlai_k" + "eleyi_com") //這樣的寫法是不正確的: $(".yuanlai_k" + "eleyi_com").appendTo('<a href="http://keley' + 'i.com" class="a_kel' + 'eyi_com">這是appendTo函數(shù)加上去的內(nèi)容</a>') }) </script> </body> </html>

結(jié)果如下:

<span class="yuanlai_keleyi_com">柯樂義,這是span里的內(nèi)容,keleyi.com。<a href="http://keleyi.com/a/bjac/2oncd079.htm">原文</a><a href="http://keleyi.com" class="a_keleyi_com">這是after函數(shù)加上去的內(nèi)容</a></span>

即:span標(biāo)簽里面多了一個(gè)a標(biāo)簽

效果和append函數(shù)是一樣,只不過它們的寫法是反著來寫的而已

appendTo函數(shù)的一個(gè)實(shí)際應(yīng)用:http://keleyi.com/a/bjac/jp71q5jt.htm

原文:http://keleyi.com/a/bjac/2oncd079.htm

轉(zhuǎn)載于:https://www.cnblogs.com/snowbaby-kang/p/3731470.html

總結(jié)

以上是生活随笔為你收集整理的转:jQ函数after、append、appendTo的区别的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。