這次帶給大家使用jQuery替換節(jié)點(diǎn)元素(附程式碼),使用jQuery替換節(jié)點(diǎn)元素的注意事項(xiàng)有哪些,下面就是實(shí)戰(zhàn)案例,一起來(lái)看一下。
<!DOCTYPE html>
<html lang="en">
<head>
?<meta charset="UTF-8">
?<title>中國(guó)</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>超實(shí)用的jquery代碼段-jquery插入節(jié)點(diǎn)元素的方法</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é)點(diǎn)元素</button>
</body>
</html>
#效果圖如下:

如圖(2 )

相信看了本文案例你已經(jīng)掌握了方法,更多精彩請(qǐng)關(guān)注php中文網(wǎng)其它相關(guān)文章!
推薦閱讀:
如何操作JS為動(dòng)態(tài)元素增加事件
JS動(dòng)態(tài)新增方法與PHP動(dòng)態(tài)新增方法比較
以上是使用jQuery替換節(jié)點(diǎn)元素(附程式碼)的詳細(xì)內(nèi)容。更多資訊請(qǐng)關(guān)注PHP中文網(wǎng)其他相關(guān)文章!