KAXU 发表于 2013-2-7 15:14:21

jquery 遍历 andSelf()

andSelf()
将之前匹配元素集合增加到当前匹配元素集合中。返回匹配元素集合
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"                     "http://www.w3.org/TR/html4/loose.dtd"><html><head><script src="http://code.jquery.com/jquery-latest.js"></script>    <script>$(document).ready(function(){      $("div").find("p").andSelf().addClass("border");    $("div").find("p").addClass("background");});</script><style>p, div { margin:5px; padding:5px; }.border { border: 2px solid red; }.background { background:yellow; }</style></head><body><div>    <p>First Paragraph</p>    <p>Second Paragraph</p></div></body></html> 
$("div").find("p").andSelf().addClass("border");
将匹配div元素集合增加到匹配p元素集合中。
页: [1]
查看完整版本: jquery 遍历 andSelf()