jQuery 文档操作方法(append) 这些方法对于 XML 文档和 HTML 文档均是适用的,除了:html()。 一、append() 方法

一、append() 方法

append() 方法在被选元素的结尾(仍然在内部)插入指定内容。

例子:

<html>
<head>
<script type="text/javascript" src="/jquery/jquery.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$("button").click(function(){
$("p").append(" <b>Hello world!</b>");
});
});
</script>
</head>
<body>
<p>This is a paragraph.</p>
<p>This is another paragraph.</p>
<button>在每个 p 元素的结尾添加内容</button>
</body>
</html>


得出结果

This is a paragraph. Hello world! Hello world! Hello world!

This is another paragraph. Hello world! Hello world! Hello world!

每次点击按钮,都会在元素内容后面添加需要的内容。