append
英 [??pend]? ?美 [??p?nd]??
vt.附加;加;貼上;簽(名)
jquery的append()方法 語(yǔ)法
作用:append() 方法在被選元素的結(jié)尾(仍在內(nèi)部)插入指定內(nèi)容。 append() 和?appendTo()?方法執(zhí)行的任務(wù)相同。不同之處在於:內(nèi)容的位置和選擇器。
語(yǔ)法:$(selector).append(content)
#參數(shù):
##參數(shù) | 描述 |
content? ?? | 必要。規(guī)定要插入的內(nèi)容(可包含 HTML 標(biāo)籤)。使用函數(shù)來(lái)附加內(nèi)容。 |
語(yǔ)法:$(selector).append(function(index,html))
參數(shù):
參數(shù) | 描述 |
#function(index,html)? | 必要。規(guī)定傳回待插入內(nèi)容的函數(shù)。 |
index? | 可選。接收選擇器的 index 位置。 |
html? | 可選。接收選擇器的目前 HTML。 |
jquery的append()方法 範(fàn)例
<html>
<head>
<script type="text/javascript" src="http://apps.bdimg.com/libs/jquery/2.1.1/jquery.min.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>在每個(gè) p 元素的結(jié)尾添加內(nèi)容</button>
</body>
</html>
執(zhí)行實(shí)例 ?#點(diǎn)擊 "執(zhí)行實(shí)例" 按鈕查看線上實(shí)例
#