jQuery中append()方法用法實例
本文實例講述了jQuery中append()方法用法。分享給大家供大家參考。具體分析如下:
此方法可向所有匹配元素的內(nèi)部的尾部追加HTML內(nèi)容。
特別說明:
此方法是追加內(nèi)容,并不會刪除之前的內(nèi)容。
html內(nèi)容就是內(nèi)容中可以包含html標簽,并且能夠被瀏覽器渲染。
文本內(nèi)容是先將內(nèi)容中的html預定義字符轉(zhuǎn)換成html字符實體,這樣html標簽就不會被渲染。
語法結構:
實例代碼:
實例一:
<!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").append("<b>好好學習</b>");
})
</script>
</head>
<body>
<div>原來內(nèi)容</div>
</body>
</html>[/size]
[size=2]
在原來div內(nèi)容的后面追加內(nèi)容。
實例二:
<!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").append("<b>好好學習</b>");
$(".text").text("<b>好好學習</b>");
})
})
</script>
</head>
<body>
<div class="html"></div>
<div class="text"></div>
<button>點擊查看效果</button>
</body>
</html>
通過此實例大家可以觀察一下HTML內(nèi)容和文本內(nèi)容的區(qū)別。
希望本文所述對大家的jQuery程序設計有所幫助。
相關文章
jQuery.parseJSON(json)將JSON字符串轉(zhuǎn)換成js對象
本節(jié)主要介紹了使用jQuery.parseJSON(json)將JSON字符串轉(zhuǎn)換成js對象,需要的朋友可以參考下2014-07-07jQuery+ajax實現(xiàn)無刷新級聯(lián)菜單示例
這篇文章主要介紹了jQuery+ajax實現(xiàn)無刷新級聯(lián)菜單示例,代碼很完整,也非常實用,有需要的小伙伴可以參考下。2015-05-05

jQuery實現(xiàn)的fixedMenu下拉菜單效果代碼

jQuery UI AutoComplete 自動完成使用小記

jquery實現(xiàn)LED廣告牌旋轉(zhuǎn)系統(tǒng)圖片切換效果代碼分享