prepend
英 [pri:'pend]? ?美 [pri:'pend]??
vt.預(yù)先考慮,預(yù)先計劃,預(yù)謀
jquery prepend() 方法 語法
作用:prepend() 方法在被選元素的開頭(仍位於內(nèi)部)插入指定內(nèi)容。 prepend() 和?prependTo()?方法作用相同。差異在於語法:內(nèi)容和選擇器的位置,以及 prependTo() 無法使用函數(shù)來插入內(nèi)容。
語法:$(selector).prepend(content)
#參數(shù):
##參數(shù) | 描述 |
content? ?? | 必要。規(guī)定要插入的內(nèi)容(可包含 HTML 標(biāo)籤)。 |
使用函數(shù)來附加內(nèi)容:使用函數(shù)在被選元素的開頭插入指定的內(nèi)容。
語法:$(selector).prepend(function(index,html))
參數(shù):
##參數(shù)描述 | |
function(index,html)?必要。規(guī)定傳回待插入內(nèi)容的函數(shù)。 | |
index可選。接受選擇器的 index 位置。 | |
html?可選。接受選擇器的目前 HTML。 | |
jquery prepend() 方法 範(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").prepend("<b>Hello world!</b> ");
});
});
</script>
</head>
<body>
<p>This is a paragraph.</p>
<p>This is another paragraph.</p>
<button>在每個 p 元素的開頭插入內(nèi)容</button>
</body>
</html>
執(zhí)行實例 ?#點擊 "執(zhí)行實例" 按鈕查看線上實例
#