jQuery使用append在html元素后同时添加多项内容的方法
本文实例讲述了jQuery使用append在html元素后同时添加多项内容的方法。分享给大家供大家参考。具体分析如下:
下面的代码可以同时在文本段落后添加多项内容
<!DOCTYPEhtml>
<html>
<head>
<scriptsrc="js/jquery.min.js">
</script>
<script>
functionappendText()
{
vartxt1="<p>Text.</p>";//CreatetextwithHTML
vartxt2=$("<p></p>").text("Text.");//CreatetextwithjQuery
vartxt3=document.createElement("p");
txt3.innerHTML="Text.";//CreatetextwithDOM
$("body").append(txt1,txt2,txt3);//Appendnewelements
}
</script>
</head>
<body>
<p>Thisisaparagraph.</p>
<buttononclick="appendText()">Appendtext</button>
</body>
</html>
希望本文所述对大家的jQuery程序设计有所帮助。