jquery 進行dom操作

來源:互聯網
上載者:User

標籤:nod   inode   jquery   ret   rem   .text   after   empty   game   

1.使用jqury進行dom操作

(1).建立節點 使用$()包住即可傳回值是jquery對象

var $liNode=$("<li></li>")

(2).把節點插入到文檔中的8個方法

1.append,appendTo    這兩個方法是插入到文檔的末尾,注意append的左邊是要被插入的對象,其他的同理可知

2.pretend,pretendTo  插入到文檔的頭

3.insertAfter,after   插入到文檔的後面

4.insertBefore,before  插入到文檔的前面

(3).刪除節點

a.remove();a被清除

(4)清空節點

a.empty();a被清空

(5)複製節點

//在紅警的下面game中複製北京
$(‘#game li:first‘).after($(‘#a1‘).clone(true).attr("id","a2"));

(6)替換節點

//建立一個位元組點替換遊戲中的紅警節點
$("<li>景德鎮</li>").replaceAll($(‘#game li:first‘));
$(‘#a1‘).replaceWith($("<li>景德鎮</li>"))

 

注意:由於replaceAll和replaceWith的傳回值不同建議優先使用replaceWith()方法

var $bj= $(‘#a1‘).clone();
//紅警被北京替換掉
var $h=$(‘#h‘).replaceWith($bj);
//背靜替換紅警;

$(‘#a1‘).replaceWith($h);

(7).val() html().text(),attr(),width(),height()都具有讀寫的方法;

 

jquery 進行dom操作

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.