jQuery中append()方法用法實(shí)例
本文實(shí)例講述了jQuery中append()方法用法。分享給大家供大家參考。具體分析如下:
此方法可向所有匹配元素的內(nèi)部的尾部追加HTML內(nèi)容。
特別說(shuō)明:
此方法是追加內(nèi)容,并不會(huì)刪除之前的內(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):
實(shí)例代碼:
實(shí)例一:
<!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").append("<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í)例二:
<!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").append("<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)于jquery append() html時(shí)的小問(wèn)題的解決方法
- jQuery中append、insertBefore、after與insertAfter的簡(jiǎn)單用法與注意事項(xiàng)
- jquery使用append(content)方法注意事項(xiàng)分享
- jQuery 追加元素的方法如append、prepend、before
- jquery append()方法與html()方法的區(qū)別及使用介紹
- jquery中append()與appendto()用法分析
- jQuery中append()方法用法實(shí)例
- jQuery中appendTo()方法用法實(shí)例
- 解決Jquery向頁(yè)面append新元素之后事件的綁定問(wèn)題
相關(guān)文章
jQuery.parseJSON(json)將JSON字符串轉(zhuǎn)換成js對(duì)象
本節(jié)主要介紹了使用jQuery.parseJSON(json)將JSON字符串轉(zhuǎn)換成js對(duì)象,需要的朋友可以參考下2014-07-07jQuery+ajax實(shí)現(xiàn)無(wú)刷新級(jí)聯(lián)菜單示例
這篇文章主要介紹了jQuery+ajax實(shí)現(xiàn)無(wú)刷新級(jí)聯(lián)菜單示例,代碼很完整,也非常實(shí)用,有需要的小伙伴可以參考下。2015-05-05

jquery attr()設(shè)置和獲取屬性值實(shí)例教程

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

EasyUI在表單提交之前進(jìn)行驗(yàn)證的實(shí)例代碼

jQuery UI AutoComplete 自動(dòng)完成使用小記

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