如何創(chuàng)建元素節(jié)點 jquery添加節(jié)點的幾種方法?
jquery添加節(jié)點的幾種方法?Append()、appendto()add child element(end)prepend()prependto()add child element(front
jquery添加節(jié)點的幾種方法?
Append()、appendto()add child element(end)prepend()prependto()add child element(front)insertbefore()、before()add horizontal element(front)insertafter()、after()add horizontal element(back)replacewith()和replaceall()用于替換節(jié)點remove()delete element empty()delete child element
Append(),appendto()添加子元素(end)prepend()prependto()添加子元素(front)insertbefore(),before()添加水平元素(front)insertafter(),after()add horizontal element(back)replacewith()和replaceall()用于替換節(jié)點remove()delete element empty()delete child element
jquery添加與刪除節(jié)點的幾種方法?
使用jQuery創(chuàng)建新元素的方法是$(HTML標(biāo)記),例如,$(“<P></P>”)創(chuàng)建段落。注意,只創(chuàng)建了對象,沒有添加到文檔節(jié)點;以下四種jQuery方法可以向文檔樹中添加新內(nèi)容:
append()-在所選元素的末尾插入內(nèi)容
prepend()-在所選元素的開頭插入內(nèi)容
after()-在所選元素的后面插入內(nèi)容
before()-在所選元素的前面插入內(nèi)容下面的示例顯示:單擊“添加”按鈕創(chuàng)建一個新的輸入文本框
1。HTML結(jié)構(gòu)
<input type=“text”id=“testuinput”><input type=“button”value=“add”/>
2。JavaScript代碼
$(function(){T/T$(“input[type=”button“]”)。單擊(function(){T/tnew)uj=$(“<input type=”text“>”)TT$(this).before(newu3。顯示效果
初始樣式
兩次單擊“添加”按鈕后的效果