久久久久久久视色,久久电影免费精品,中文亚洲欧美乱码在线观看,在线免费播放AV片

<center id="vfaef"><input id="vfaef"><table id="vfaef"></table></input></center>

    <p id="vfaef"><kbd id="vfaef"></kbd></p>

    
    
    <pre id="vfaef"><u id="vfaef"></u></pre>

      <thead id="vfaef"><input id="vfaef"></input></thead>

    1. 站長資訊網(wǎng)
      最全最豐富的資訊網(wǎng)站

      jquery怎么替換dom元素

      方法:1、利用replaceWith()方法,該方法用于集合中所有匹配的元素,語法為“元素對象.replaceWith(content,function(index))”;2、利用replaceAll()方法,該方法用于把被選元素替換為新的HTML元素,語法為“元素對象.replaceAll(selector)”。

      jquery怎么替換dom元素

      本教程操作環(huán)境:windows10系統(tǒng)、jquery3.4.1版本、Dell G3電腦。

      jquery怎么替換dom元素

      1、replaceWith() 方法

      $(selector).replaceWith(content,function(index))

      content 必需。規(guī)定要插入的內(nèi)容(可包含 HTML 標(biāo)簽)。

      可能的值:

      • HTML 元素

      • jQuery 對象

      • DOM 元素

      function(index) 可選。規(guī)定返回替換內(nèi)容的函數(shù)。

      index – 返回集合中元素的 index 位置。

      $(DOM).replaceWith(newContent) 用于替換集合中所有匹配的元素,并且返回被刪除的元素集合:

      <!DOCTYPE html> <html> <head> <title></title> <script src="jquery.js"></script> <script type="text/javascript"> $('document').ready(function (){ $('body>input').click(function (){ $('body>ul>li:gt(1)').replaceWith('<li>替換后的元素</li>') }) }) </script> </head> <body> <input type="button" value="替換"> <ul> <li>第一個(gè)</li> <li>第二個(gè)</li> <li>第三個(gè)</li> <li>第四個(gè)</li> </ul> </body> </html>

      輸出結(jié)果:

      jquery怎么替換dom元素

      2、replaceAll() 方法

      $(newContent).replaceAll(DOM) 與 $(DOM).replaceWith(newContent) 方法功能一樣,只不過是參數(shù)位置調(diào)換了一下(可以直接在后面賦予樣式):

      <!DOCTYPE html> <html> <head> <title></title> <script src="jquery.js"></script> <script type="text/javascript"> $('document').ready(function (){ $('body>input').click(function (){ $('<li>替換后的元素</li>').replaceAll('body>ul>li:gt(1)').css('color','orange'); }) }) </script> </head> <body> <input type="button" value="替換"> <ul> <li>第一個(gè)</li> <li>第二個(gè)</li> <li>第三個(gè)</li> <li>第四個(gè)</li> </ul> </body> </html>

      輸出結(jié)果:

      jquery怎么替換dom元素

      視頻教程推薦:jQuery視頻教程

      贊(0)
      分享到: 更多 (0)
      網(wǎng)站地圖   滬ICP備18035694號-2    滬公網(wǎng)安備31011702889846號