jQuery中wrapInner()方法用法實例
更新時間:2015年01月16日 14:32:23 投稿:shichen2014
這篇文章主要介紹了jQuery中wrapInner()方法用法,實例分析了wrapInner()方法的功能、定義及包裹匹配元素的使用技巧,需要的朋友可以參考下
本文實例講述了jQuery中wrapInner()方法用法。分享給大家供大家參考。具體分析如下:
此方法使用指定的HTML內容或元素將匹配的元素內容包裹起來。
語法一:
用指定的DOM元素去包裹匹配元素的內容。
復制代碼 代碼如下:
$(selector).wrapInner(elem)
參數列表:
實例:
復制代碼 代碼如下:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="author" content="http://m.fzitv.net/" />
<head>
<title>腳本之家</title>
<style type="text/css">
div
{
width:200px;
height:200px;
border:1px solid blue;
}
p
{
width:150px;
height:150px;
border:1px solid red;
}
</style>
<script type="text/javascript" src="mytest/jQuery/jquery-1.8.3.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$("button").click(function(){
$("div").wrapInner(document.createElement("p"));
});
});
</script>
</head>
<body>
<div>這是div的內容,將會被包裹</div>
<div>這是div的內容,將會被包裹</div>
<button>用div包裹每個段落</button>
</body>
</html>
語法二:
用函數返回用于包裹匹配元素內容的元素。
復制代碼 代碼如下:
$(selector).wrapInner(function)
參數列表:
復制代碼 代碼如下:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="author" content="http://m.fzitv.net/" />
<head>
<title>腳本之家</title>
<style type="text/css">
div
{
width:200px;
height:200px;
border:1px solid blue;
}
p
{
width:150px;
height:150px;
border:1px solid red;
}
</style>
<script type="text/javascript" src="mytest/jQuery/jquery-1.8.3.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$("button").click(function(){
$("div").wrapInner(function(){
return "<p></p>"
});
});
});
</script>
</head>
<body>
<div>這是div的內容,將會被包裹</div>
<div>這是div的內容,將會被包裹</div>
<button>用div包裹每個段落</button>
</body>
</html>
語法三:
用html標記代碼包裹匹配元素的內容。
復制代碼 代碼如下:
$(selector).wrapInner(html)
參數列表:
實例:
復制代碼 代碼如下:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="author" content="http://m.fzitv.net/" />
<head>
<title>腳本之家</title>
<style type="text/css">
div
{
width:200px;
height:200px;
border:1px solid blue;
}
p
{
width:150px;
height:150px;
border:1px solid red;
}
</style>
<script type="text/javascript" src="mytest/jQuery/jquery-1.8.3.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$("button").click(function(){
$("div").wrapInner("<p></p>");
});
});
</script>
</head>
<body>
<div>這是div的內容,將會被包裹</div>
<div>這是div的內容,將會被包裹</div>
<button>用div包裹每個段落</button>
</body>
</html>
希望本文所述對大家的jQuery程序設計有所幫助。
本文轉自:螞蟻部落http://www.softwhy.com/
相關文章
jquery中$(#form :input)與$(#form input)的區(qū)別
本節(jié)為大家介紹下jquery 中$(#form :input)與$(#form input)的區(qū)別,需要的朋友可以參考下2014-08-08
jQuery leonaScroll 1.1 自定義滾動條插件(推薦)
這篇文章主要介紹了jQuery leonaScroll 1.1 自定義滾動條插件(推薦)的相關資料,非常不錯,具有參考借鑒價值,需要的朋友可以參考下2016-09-09
jquery api參考 visualjquery 中國線路 速度快
jquery api參考 visualjquery 中國線路 速度快...2007-11-11
jQuery插件ImageDrawer.js實現動態(tài)繪制圖片動畫(附源碼下載)
ImageDrawer.js是一款可以實現動態(tài)繪制圖片動畫的jQuery插件,接下來通過本文給大家介紹jQuery插件ImageDrawer.js實現動態(tài)繪制圖片動畫(附源碼下載),需要的朋友參考下2016-02-02

