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

jQuery操作元素追加內容示例

 更新時間:2020年01月10日 09:30:37   作者:qq_42412646  
這篇文章主要介紹了jQuery操作元素追加內容,結合完整實例形式分析了jquery頁面元素追加相關操作方法,包括append、appendTo、prepend、prependTo等方法使用技巧,需要的朋友可以參考下

本文實例講述了jQuery操作元素追加內容。分享給大家供大家參考,具體如下:

<html>
 <head>
 <title>jQuery操作文檔結構</title>
 <meta charset="UTF-8"/>
 <script src="http://libs.baidu.com/jquery/1.9.1/jquery.min.js"></script>
 <script type="text/javascript">
  //內部的操作
  function testAppend(){
  //獲取需要操作的對象
  var showdiv=$("#showdiv");
  //進行添加操作,指定內容的追加
  showdiv.append("<b>賽高</b>");  //在對象內部的后面添加指定的內容,其是html可解析的內容,和html不同的是:html重新賦值(覆蓋)這個在內容后面追加
  }
  function testAppend2(){
  //獲取需要操作的對象
  var u2=$("#u2");
  //進行添加操作,指定內容的追加
//  u2.appendTo("#show01");  //在對象的內部后面添加利用選擇器選擇的對象內容,把前面的對象移動到后面的對象的內部后面(一個剪切復制操作)
  $("#u2").appendTo(show01);
  }
  function testprepend(){
  //獲取需要操作的對象
  var showdiv=$("#showdiv");
  //進行添加操作,指定內容的追加
  showdiv.prepend("<i>境界的彼方</i>"); //在對象的內部前面添加內容
  }
  function testprependTo(){
  //獲取需要操作的對象
  var showdiv=$("#showdiv");
  //進行添加操作,指定內容的追加
  $("#u2").prependTo(showdiv); //在對象的內部前面添加選擇器的對象(移動到)
//  showdiv.prependTo("#u2");
  }
  //外部插入
  function testAfter1(){
  //獲取需要操作的對象
  var showdiv=$("#showdiv");
  //進行添加操作,指定內容的追加
  showdiv.after("<b>もちろん</b>"); //在對象的外部的后面添加內容
  }
  function testAfter2(){
  //獲取需要操作的對象
  var showdiv=$("#showdiv");
  //進行添加操作,指定內容的追加
  $("#u2").insertAfter(showdiv); //在對象的外部的后面添加選擇器的對象(移動到)
//  showdiv.prependTo("#u2");
  }
  function testBefore1(){
  //獲取需要操作的對象
  var showdiv=$("#showdiv");
  //進行添加操作,指定內容的追加
  showdiv.before("<b>もちろん</b>"); //在對象的外部的前面添加內容
  }
  function testBefore2(){
  //獲取需要操作的對象
  var showdiv=$("#showdiv");
  //進行添加操作,指定內容的追加
  $("#u2").insertBefore(showdiv); //在對象的內部前面添加選擇器的對象
//  showdiv.prependTo("#u2");
  }
 </script>
 <style type="text/css">
  #showdiv{
  width: 300px;
  height: 300px;
  border: solid 1px;
  }
  #show01{
  width: 300px;
  height: 300px;
  border: solid 1px;
  }
 </style>
 </head>
 <body>
 <h3>jQuery操作文檔結構</h3>
 <h4>內部操作</h4>
 <input type="button" name="" id="" value="測試追加內容--append" onclick="testAppend()"/>
 <input type="button" name="" id="" value="測試移動內容--appendTo" onclick="testAppend2()"/>
 <input type="button" name="" id="" value="測試追加內容--prepend" onclick="testprepend()"/>
 <input type="button" name="" id="" value="測試移動內容--prependTo" onclick="testprependTo()"/>
 <hr />
 <h4></h4>
 <input type="button" name="" id="" value="測試追加內容--after" onclick="testAfter1()"/>
 <input type="button" name="" id="" value="測試移動內容--after" onclick="testAfter2()"/>
 <input type="button" name="" id="" value="測試追加內容--before" onclick="testBefore1()"/>
 <input type="button" name="" id="" value="測試移動內容--before" onclick="testBefore2()"/>
 <hr />
 <div id="showdiv">
  <i>Clannad</i>
 </div><br /><br />
 <div id="show01">
  <!--<u>Clannad After Story</u>-->
 </div>
 <span id="u2"><u>Clannad After Story</u></span>
 <hr /> 
 </body>
</html>

感興趣的朋友可以使用在線HTML/CSS/JavaScript代碼運行工具http://tools.jb51.net/code/HtmlJsRun測試上述代碼運行效果。

更多關于jQuery相關內容感興趣的讀者可查看本站專題:《jQuery頁面元素操作技巧匯總》、《jQuery常見事件用法與技巧總結》、《jQuery常用插件及用法總結》、《jQuery擴展技巧總結》及《jquery選擇器用法總結

希望本文所述對大家jQuery程序設計有所幫助。

相關文章

最新評論