jQuery.andSelf()方法在jQuery中做什么?
andSelf()方法将先前的选择添加到当前选择中。当脚本中有多个遍历,然后添加在上一个遍历之前匹配的内容时,该方法很有用。
示例
您可以尝试运行以下代码来学习如何使用jQuery.andSelf()方法:
<html>
<head>
<title>jQuery andSelf() method</title>
<script src = "https://cdn.staticfile.org/jquery/2.1.3/jquery.min.js"></script>
<script>
$(document).ready(function(){
$("div").find("p").andSelf().addClass("border");
});
</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>热门推荐
10 财运虎年祝福语简短语
11 单亲爸爸春节祝福语简短
12 狗狗上厕所训练
13 植物种植祝福语简短
14 翻译考试祝福语朋友简短
15 个人周年庆简短祝福语
16 狗狗怎么训练
17 分别祝福语简短搞笑英文
18 生日广州男生祝福语简短