<!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">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta content="https://www.jb51.net/" />
<title>脚本之家</title>
<style type="text/css">
ul
{
width:200px;
height:200px;
border:1px solid blue;
}
div
{
height:300px;
}
</style>
<script type="text/javascript" src="https://www.jb51.net/mytest/jQuery/jquery-1.8.3.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$("p").add($("#myspan")).css("color","green")
})
</script>
</head>
<body>
<div>
<ul>
<li>
<p>我是p</p>
</li>
<span>我是span</span>
</ul>
<span>我是span</span> </div>
</body>
</html>
语法三:
复制代码 代码如下:
$(selector).add(html)
参数列表:
参数 描述
html 可选。被添加的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">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta content="https://www.jb51.net/" />
<title>脚本之家</title>
<script type="text/javascript" src="https://www.jb51.net/mytest/jQuery/jquery-1.8.3.js"></script>
<script type="text/javascript">
$(document).ready(function(){
alert($("p").add("<span>新添加的</span>").length);
})
</script>
</head>
<body>
<div>
<ul>
<li>
<p>我是p</p>
</li>
</ul>
</body>
</html>