before

英[b??f?:(r)]? ?美[b??f?r,-?for]??

prep.在…之前;先於,優(yōu)於;當(dāng);著…的面;與其…

conj.在…之前;在…以前;比…早些;與其…

adv.先前,從前;在前,在前方

jquery before()方法 語(yǔ)法

作用:before() 方法在被選元素前插入指定的內(nèi)容。

語(yǔ)法:$(selector).before(content)

#參數(shù):

##參數(shù)描述content#必要。規(guī)定要插入的內(nèi)容(可包含 HTML 標(biāo)籤)。

使用函數(shù)來插入內(nèi)容:使用函數(shù)在指定的元素前面插入內(nèi)容。

語(yǔ)法:$(selector).before(function(index))

參數(shù):

參數(shù)描述function(index)?必要。規(guī)定傳回待插入內(nèi)容的函數(shù)。 index?可選。接收選擇器的 index 位置。

jquery before()方法 範(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(){
  $(".btn1").click(function(){
    $("p").before("<p>Hello world!</p>");
  });
});
</script>
</head>
<body>
<p>This is a paragraph.</p>
<button class="btn1">在每個(gè)段落前面插入新的段落</button>
</body>
</html>
執(zhí)行實(shí)例 ?

#點(diǎn)擊 "執(zhí)行實(shí)例" 按鈕查看線上實(shí)例

#
    <i id="44sq2"></i>
    <span id="44sq2"></span>
    <label id="44sq2"></label>
      <center id="44sq2"></center>
      <rt id="44sq2"></rt>