欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

jQuery中prepend()方法用法實(shí)例

 更新時(shí)間:2014年12月25日 10:42:43   投稿:shichen2014  
這篇文章主要介紹了jQuery中prepend()方法用法,以實(shí)例形式較為詳細(xì)的分析了prepend()方法的功能、定義及使用技巧,并對(duì)比分析了與text()方法的不同之處,需要的朋友可以參考下

本文實(shí)例講述了jQuery中prepend()方法用法。分享給大家供大家參考。具體分析如下:

此方法可向所有匹配元素的內(nèi)部的前面追加HTML內(nèi)容。

特別說(shuō)明:

此方法是追加內(nèi)容,也就是原來(lái)的內(nèi)容還在。
HTML內(nèi)容就是內(nèi)容中可以包含HTML標(biāo)簽,并且能夠被瀏覽器渲染。
文本內(nèi)容是先將內(nèi)容中的html預(yù)定義字符轉(zhuǎn)換成html字符實(shí)體,這樣html標(biāo)簽就不會(huì)被渲染。

語(yǔ)法結(jié)構(gòu):

復(fù)制代碼 代碼如下:
$(selector).prepend(content)

實(shí)例代碼:
實(shí)例一:

復(fù)制代碼 代碼如下:

<!DOCTYPE html>
<html>
<head>
<meta charset=" utf-8">
<meta name="author" content="http://www.dbjr.com.cn/" />
<title>腳本之家</title>
<style type="text/css">
div
{
  height:150px;
  width:150px;
  background-color:green;
  margin-top:10px;
}
</style>
<script type="text/javascript" src="mytest/jQuery/jquery-1.8.3.js"></script>
<script type="text/javascript">
$(document).ready(function(){
  $("div").prepend("<b>  好好學(xué)習(xí)</b>");
})
</script>
</head>
<body>
<div>原來(lái)內(nèi)容</div>
</body>
</html>[/size]
[size=2]

在原來(lái)div內(nèi)容的前面追加內(nèi)容。
實(shí)例二:

復(fù)制代碼 代碼如下:

<!DOCTYPE html>
<html>
<head>
<meta charset=" utf-8">
<meta name="author" content="http://www.dbjr.com.cn/" />
<title>腳本之家</title>
<style type="text/css">
div
{
  height:150px;
  width:150px;
  background-color:green;
  margin-top:10px;
}
</style>
<script type="text/javascript" src="mytest/jQuery/jquery-1.8.3.js"></script>
<script type="text/javascript">
$(document).ready(function(){ 
  $("button").click(function(){
    $(".html").prepend("<b>好好學(xué)習(xí)</b>");
    $(".text").text("<b>好好學(xué)習(xí)</b>");    
  })
})
</script>
</head>
<body>
<div class="html"></div>
<div class="text"></div>
<button>點(diǎn)擊查看效果</button>
</body>
</html>

通過(guò)此實(shí)例大家可以觀察一下html內(nèi)容和文本內(nèi)容的區(qū)別。

希望本文所述對(duì)大家的jQuery程序設(shè)計(jì)有所幫助。

相關(guān)文章

最新評(píng)論