欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

jQuery操作元素追加內(nèi)容示例

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

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

<html>
 <head>
 <title>jQuery操作文檔結(jié)構(gòu)</title>
 <meta charset="UTF-8"/>
 <script src="http://libs.baidu.com/jquery/1.9.1/jquery.min.js"></script>
 <script type="text/javascript">
  //內(nèi)部的操作
  function testAppend(){
  //獲取需要操作的對(duì)象
  var showdiv=$("#showdiv");
  //進(jìn)行添加操作,指定內(nèi)容的追加
  showdiv.append("<b>賽高</b>");  //在對(duì)象內(nèi)部的后面添加指定的內(nèi)容,其是html可解析的內(nèi)容,和html不同的是:html重新賦值(覆蓋)這個(gè)在內(nèi)容后面追加
  }
  function testAppend2(){
  //獲取需要操作的對(duì)象
  var u2=$("#u2");
  //進(jìn)行添加操作,指定內(nèi)容的追加
//  u2.appendTo("#show01");  //在對(duì)象的內(nèi)部后面添加利用選擇器選擇的對(duì)象內(nèi)容,把前面的對(duì)象移動(dòng)到后面的對(duì)象的內(nèi)部后面(一個(gè)剪切復(fù)制操作)
  $("#u2").appendTo(show01);
  }
  function testprepend(){
  //獲取需要操作的對(duì)象
  var showdiv=$("#showdiv");
  //進(jìn)行添加操作,指定內(nèi)容的追加
  showdiv.prepend("<i>境界的彼方</i>"); //在對(duì)象的內(nèi)部前面添加內(nèi)容
  }
  function testprependTo(){
  //獲取需要操作的對(duì)象
  var showdiv=$("#showdiv");
  //進(jìn)行添加操作,指定內(nèi)容的追加
  $("#u2").prependTo(showdiv); //在對(duì)象的內(nèi)部前面添加選擇器的對(duì)象(移動(dòng)到)
//  showdiv.prependTo("#u2");
  }
  //外部插入
  function testAfter1(){
  //獲取需要操作的對(duì)象
  var showdiv=$("#showdiv");
  //進(jìn)行添加操作,指定內(nèi)容的追加
  showdiv.after("<b>もちろん</b>"); //在對(duì)象的外部的后面添加內(nèi)容
  }
  function testAfter2(){
  //獲取需要操作的對(duì)象
  var showdiv=$("#showdiv");
  //進(jìn)行添加操作,指定內(nèi)容的追加
  $("#u2").insertAfter(showdiv); //在對(duì)象的外部的后面添加選擇器的對(duì)象(移動(dòng)到)
//  showdiv.prependTo("#u2");
  }
  function testBefore1(){
  //獲取需要操作的對(duì)象
  var showdiv=$("#showdiv");
  //進(jìn)行添加操作,指定內(nèi)容的追加
  showdiv.before("<b>もちろん</b>"); //在對(duì)象的外部的前面添加內(nèi)容
  }
  function testBefore2(){
  //獲取需要操作的對(duì)象
  var showdiv=$("#showdiv");
  //進(jìn)行添加操作,指定內(nèi)容的追加
  $("#u2").insertBefore(showdiv); //在對(duì)象的內(nèi)部前面添加選擇器的對(duì)象
//  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操作文檔結(jié)構(gòu)</h3>
 <h4>內(nèi)部操作</h4>
 <input type="button" name="" id="" value="測(cè)試追加內(nèi)容--append" onclick="testAppend()"/>
 <input type="button" name="" id="" value="測(cè)試移動(dòng)內(nèi)容--appendTo" onclick="testAppend2()"/>
 <input type="button" name="" id="" value="測(cè)試追加內(nèi)容--prepend" onclick="testprepend()"/>
 <input type="button" name="" id="" value="測(cè)試移動(dòng)內(nèi)容--prependTo" onclick="testprependTo()"/>
 <hr />
 <h4></h4>
 <input type="button" name="" id="" value="測(cè)試追加內(nèi)容--after" onclick="testAfter1()"/>
 <input type="button" name="" id="" value="測(cè)試移動(dòng)內(nèi)容--after" onclick="testAfter2()"/>
 <input type="button" name="" id="" value="測(cè)試追加內(nèi)容--before" onclick="testBefore1()"/>
 <input type="button" name="" id="" value="測(cè)試移動(dòng)內(nèi)容--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代碼運(yùn)行工具http://tools.jb51.net/code/HtmlJsRun測(cè)試上述代碼運(yùn)行效果。

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

希望本文所述對(duì)大家jQuery程序設(shè)計(jì)有所幫助。

相關(guān)文章

最新評(píng)論