$("p").append(function(n)是單個添加。
<html>
<head>
<script type="text/javascript" src="/jquery/jquery.js"></script>
<script type="text/javascript">
$(document).ready(function(){
? $("button").click(function(){
? ? $("p").append(function(n){
? ? ? return "<br/>" + "<b>This p element has index " + n + "</b>";
? ? });
? });
});
</script>
</head>
<body>
<h1>This is a heading</h1>
<p>This is a paragraphAAA.</p>
<button>在每個 p 元素的結(jié)尾添加內(nèi)容</button>
</body>
</html>
2018-10-06
因為你只有一個p標(biāo)簽,你每次只是在這唯一的p標(biāo)簽里添加了一個br標(biāo)簽,br標(biāo)簽個數(shù)在增加,p標(biāo)簽個數(shù)還是1
2018-03-14
before也不累加