亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

jQuery中prepend()方法用法實例

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

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

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

特別說明:

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

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

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

實例代碼:
實例一:

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

<!DOCTYPE html>
<html>
<head>
<meta charset=" utf-8">
<meta name="author" content="http://chabaoo.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>原來內(nèi)容</div>
</body>
</html>[/size]
[size=2]

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

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

<!DOCTYPE html>
<html>
<head>
<meta charset=" utf-8">
<meta name="author" content="http://chabaoo.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>點擊查看效果</button>
</body>
</html>

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

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

相關(guān)文章

最新評論