<!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" />
<title>index</title>
<style type="text/css">
*{ margin:0; padding:0}
div{ margin:0 auto}
ul{ list-style:none}
li{ margin:4px;}
.alt{ border:2px solid #F00}
.title{border:2px solid #00f}
</style>
<script type="text/javascript" src="jquery-1.9.1.js"></script>
<script type="text/javascript">
$(function(){
//通过add()方法添加更多元素到包装集
//$("img[alt],img[title]").css("background","green")
//通过add方法实现上边的效果
$("<p>这是一个p元素</p>").appendTo("#div1")
$("img[alt]").add($("img[title]")).add("p").css("background","green")
})
</script>
</head>
<body>
<img src="#" alt="tuxiang" class="alt" />
<img src="#" title="tuxiang" class="title"/>
<img src="#" />
<img src="#" alt="tuxiang" class="alt"/>
<img src="#" />
<div id="div1"></div>
</body>
</html>
联系客服