jQuery中after()方法用法實例
本文實例講述了jQuery中after()方法用法。分享給大家供大家參考。具體分析如下:
此方法可向每個匹配元素的外部的尾部追加HTML內(nèi)容。
特別說明:
此方法是追加內(nèi)容,也就是原來的內(nèi)容還在。
HTML內(nèi)容就是內(nèi)容中可以包含HTML標簽,并且能夠被瀏覽器渲染。
文本內(nèi)容是先將內(nèi)容中的HTML預定義字符轉(zhuǎn)換成html字符實體,這樣HTML標簽就不會被渲染。
語法結(jié)構(gòu):
實例代碼:
實例一:
<!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").after("<b> 好好學習</b>");
})
</script>
</head>
<body>
<div></div>
</body>
</html>
在原來div內(nèi)容的后面追加內(nèi)容。
實例二:
<!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").after("<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程序設計有所幫助。
相關(guān)文章
JQuery中attr屬性和jQuery.data()學習筆記【必看】
下面小編就為大家?guī)硪黄狫Query中attr屬性和jQuery.data()學習筆記【必看】。小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考,一起跟隨小編過來看看吧2016-05-05
jQuery ajax請求返回list數(shù)據(jù)動態(tài)生成input標簽,并把list數(shù)據(jù)賦值到input標簽
這篇文章主要介紹了jQuery ajax請求返回list數(shù)據(jù)動態(tài)生成input標簽,并把list數(shù)據(jù)賦值到input標簽的相關(guān)資料,需要的朋友可以參考下2016-03-03
jQuery+CSS實現(xiàn)一個側(cè)滑導航菜單代碼
側(cè)滑菜單在網(wǎng)站設計中應用比較廣泛,在許多網(wǎng)站上都可以看到此種類型的菜單。本文給大家介紹jQuery+CSS實現(xiàn)一個側(cè)滑導航菜單代碼,需要的朋友參考下吧2016-05-05
jQuery實現(xiàn)鏈接的title快速出現(xiàn)的方法
這篇文章主要介紹了jQuery實現(xiàn)鏈接的title快速出現(xiàn)的方法,非常不錯,具有參考借鑒價值,需要的朋友可以參考下2017-02-02

