jQuery替換節(jié)點元素的操作方法
更新時間:2018年03月18日 16:47:47 作者:abernhong
這篇文章通過實例代碼給大家講解了jquery替換節(jié)點元素的操作方法及動態(tài)頁面的實現(xiàn)代碼,非常不錯,需要的朋友參考下吧
替換節(jié)點元素的操作,實現(xiàn)動態(tài)頁面的,代碼如下
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>中國</title>
<script type="text/javascript" src="../jquery-3.3.1/jquery-3.3.1.js"></script>
<script type="text/javascript">
$(document).ready(function () {
$("button#button-replaceWith").click(function () {
$("p").replaceWith("<strong>您好!我最喜歡的IT公司是:</strong>");
$("[name='name-replace']").replaceWith("<tr><td>name-replace</td><td>name-replace</td><td>name-replace</td></tr><tr><td>name-replace</td><td>name-replace</td><td>name-replace</td></tr>");
});
});
</script>
</head>
<body>
<h2>超實用的jquery代碼段-jquery插入節(jié)點元素的方法</h2>
<p>您好!您最喜歡的IT公司是:</p>
<ul>
<li title="Google">Google</li>
<li title="Apple">Apple</li>
<li title="Microsoft">Microsoft</li>
</ul>
<table name="name-replace">
</table>
<button id="button-replaceWith">替換節(jié)點元素</button>
</body>
</html>
效果圖如下:

如圖(1)

如圖(2)

總結
以上所述是小編給大家介紹的jQuery替換節(jié)點元素的操作方法,希望對大家有所幫助,如果大家有任何疑問歡迎給我留言,小編會及時回復大家的!
相關文章
JQuery魔力之$("tagName")與selector
DOM 中的 getElementsByTagName()方法在JQuery中的表現(xiàn)就是$(“tagName”)這么簡單!tag標簽(可以是:p、div、button …)標簽本身具有ID、Class等屬性2012-03-03
jQuery scroll事件實現(xiàn)監(jiān)控滾動條分頁示例
這篇文章主要介紹了jQuery scroll事件實現(xiàn)監(jiān)控滾動條分頁簡單示例,使用ajax加載,同時介紹了(document).height()與$(window).height()的區(qū)別,需要的朋友可以參考下2014-04-04

