本文實例講述了jQuery使用append在html元素后同時添加多項內容的方法。分享給大家供大家參考。具體分析如下:
下面的代碼可以同時在文本段落后添加多項內容
<!DOCTYPE html><html><head><script src="js/jquery.min.js"></script><script>function appendText(){var txt1="<p>Text.</p>"; // Create text with HTMLvar txt2=$("<p></p>").text("Text."); // Create text with jQueryvar txt3=document.createElement("p");txt3.innerHTML="Text."; // Create text with DOM$("body").append(txt1,txt2,txt3); // Append new elements}</script></head><body><p>This is a paragraph.</p><button onclick="appendText()">Append text</button></body></html>
希望本文所述對大家的jQuery程序設計有所幫助。
新聞熱點
疑難解答