jQuery? insertAfter() ? insertBefore()? ?????.
?? ?? ??? ????, jQuery? ??? ??? ???? ?? ??? ??? ??? ??? ??? insertAfter ? insertBefore?? ? ?? ??? ???? ??????
before() ? .insertBefore(). ?? ???? ??(??? ?? ? ??)???. before()? ?? ?? ???? ?? ?? ?? ??? ?? ??? ???? ?? .insertBefore()? ????? ??? ??? ?? ???? ?? ?????. ????
after() ? .insertAfter()? ??? ??? ??? ?????. ?? ???? ??, ?? (???) ??? ? ??? ?????. after()? ?? ?? ???? ?? ?? ?? ????? ??? ?????. .insertAfter()? ??, ??? ???? ??? ?? ??? ????
before, after ? insertBefore? ?? ?? ?????. ??? ??? ?? ??? insertAfter? ?? ???? ??? ???? ????.
??:
insertAfter? ??? ?? ?? JQuery? ???? ??? ?????. ?? ??? ?? JQuery ??? ?????.
insertBefore? ??? ?? ?? JQuery? ???? ??? ?????. ?? ?? ??? ??? ?? ??? ??? ??? ?? ?????.
???? ??? ??? ?????.
<!DOCTYPE html> <html> <head> <meta charset="utf-8" /> <title></title> <script src="http://lib.sinaapp.com/js/jquery/1.9.1/jquery-1.9.1.min.js"></script> <style> .test1 { background: #bbffaa; } .test2 { background: yellow; } </style> </head> <body> <button id="bt1">insertBefore添加元素</button> <button id="bt2">insertAfter添加元素</button> <div class="aaron"> <p class="test1">php 中文網(wǎng)</p> </div> <div class="test2">php.cn</p> </div> <script type="text/javascript"> $("#bt1").on('click', function() { //在test1元素前后插入集合中每個(gè)匹配的元素 //不支持多參數(shù) $('<p style="color:red">測(cè)試insertBefore方法增加</p>', '<p style="color:red">多參數(shù)</p>').insertBefore($(".test1")) }) </script> <script type="text/javascript"> $("#bt2").on('click', function() { //在test2元素前后插入集合中每個(gè)匹配的元素 //不支持多參數(shù) $('<p style="color:red">測(cè)試insertAfter方法增加</p>', '<p style="color:red">多參數(shù)</p>').insertAfter($(".test2")) }) </script> </body> </html>
????? ???? ???? ?????