jQuery:節點(插入,複製,替換,刪除)操作

來源:互聯網
上載者:User

標籤:

<html> <head>    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">    <title>jQuery插入,複製、替換和刪除節點</title> <script type="text/javascript" src="jquery-1.3.2.js"></script> <script type="text/javascript">    $(document).ready(function(){      //幾種添加節點的方法     //$("p").append("<b>你好嗎?</b>");//向p元素中追加《b》     //$("<b>你好嗎?</b>").appendTo("p");//將《b》追加到p元素中     //$("p").prepend("<b>你好嗎?</b>");//向p中前置《b》     //$("<b>你好嗎?</b>").prependTo("p");//將《b》前置到p元素中     //$("p").after("<b>你好嗎?</b>");//向p元素後插入《b》     //$("<b>你好嗎?</b>").insertAfter("p");//將《b》插入到p元素後邊     //$("p").before("<b>你好嗎?</b>");//在p元素之前添加《b》     //$("<b>你好嗎?</b>").insertBefore("p");//將《b》插入到p元素前面          //幾種刪除節點的方法     //var $li=$("ul li:eq(1)").remove();//刪除ul節點中第2個元素節點     //$("ul").append($li);//把剛刪除的元素節點從新添加到ul元素中去     //$("ul li").remove("li[title!=菠蘿]");//將ul元素下title屬性不等於"菠蘿"的li元素刪除     //$("ul li:eq(1)").empty();//清空ul節點下第2個li元素的內容     //複製節點    /* $("ul li").click(function(){      $(this).clone(true).appendTo("ul");//複製當前點擊的節點,並將它追加到《ul》元素中,當添加參數時複製它的事件     });     */     //替換節點    // $("p").replaceWith("<strong>你最不喜歡的水果是?</Strong>");      }); </script> </head> <body>    <p>你好!</p>    你最喜歡的水果是?    <ul>     <li title="蘋果">蘋果</li>     <li title="橘子">橘子</li>     <li title="菠蘿">菠蘿</li>     </ul> </body> </html> 

 

jQuery:節點(插入,複製,替換,刪除)操作

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.