亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

jQuery中的insertBefore(),insertAfter(),after(),before()區(qū)別介紹

 更新時(shí)間:2016年09月01日 13:44:49   作者:小碼農(nóng)雯  
這篇文章主要介紹了jQuery中的insertBefore(),insertAfter(),after(),before()區(qū)別介紹的相關(guān)資料,非常不錯(cuò),具有參考借鑒價(jià)值,需要的朋友可以參考下

insertBefore():a.insertBefore(b)

       a在前,b在后,

       a:是一個(gè)選擇器,b:也是一個(gè)選擇器

<!DOCTYPE html>
<html>
<head>
<meta charset='UTF-8'>
<title>jqu</title>
<script type="text/javascript" src='jquery-2.2.0.min.js'></script>
</head>
<body>
<p class='p1'>p1:hello</p>
hello world
<p class='p2'>p2:wenwen</p>
hello wo
</body>
<script type="text/javascript">
$(function(){
$('.p2').insertBefore('.p1');
})
</script>
</html> 

得到:

p2:wenwen
p1:hello
hello world hello wo 

insertAfter():跟insertBefore()是一樣的道理

      a.insertAfter(b)

      a在后,b在前

現(xiàn)在是說before()

before():a.before()

     a是頁面上已有的選擇器,b是你需要添加的內(nèi)容,注意:是什么就是什么,會(huì)識別標(biāo)簽,b不是一個(gè)選擇器

     a在后,b在前

<!DOCTYPE html>
<html>
<head>
<meta charset='UTF-8'>
<title>jqu</title>
<script type="text/javascript" src='jquery-2.2.0.min.js'></script>
</head>
<body>
<p class='p1'>p1:hello</p>
<p class='p2'>p2:wenwen</p>
</body>
<script type="text/javascript">
$(function(){
$('.p2').before('.p1');
})
</script>
</html> 

最后得到:

p1:hello
.p1
p2:wenwen 

看到嗎?.p1并不識別選擇器,直接就是字符串,在.p2選擇器的前面位置

after():跟before()是同理的,只是一個(gè)在前一個(gè)在后

我只是想說insertBefore(),insertAfter()跟before(),after()的區(qū)別,我感覺最大一個(gè)區(qū)別就是看你要用到的場景,你要是需要兩個(gè)選擇器的位置調(diào)換就用

insertBefore(),insertAfter()

要是需要一個(gè)選擇器跟一個(gè)文本進(jìn)行調(diào)換位置就可以用before(),after();當(dāng)然這個(gè)不只是調(diào)換位置啦

調(diào)換位置是說頁面上已經(jīng)存在的東西,這個(gè)方法里面也可以加頁面上沒有的東西,比如:

$('<p class='p3'>嘿嘿</p>').insertBefore('.p1');

以上所述是小編給大家介紹的jQuery中的insertBefore(),insertAfter(),after(),before()區(qū)別介紹,希望對大家有所幫助,如果大家有任何疑問請給我留言,小編會(huì)及時(shí)回復(fù)大家的。在此也非常感謝大家對腳本之家網(wǎng)站的支持!

相關(guān)文章

最新評論