当前位置: 移动技术网 > IT编程>开发语言>JavaScript > jQuery使用append在html元素后同时添加多项内容的方法教程

jQuery使用append在html元素后同时添加多项内容的方法教程

2019年05月17日  | 移动技术网IT编程  | 我要评论

本文实例讲述了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 html
var txt2=$("<p></p>").text("text."); // create text with jquery
var 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>

如对本文有疑问, 点击进行留言回复!!

相关文章:

验证码:
移动技术网