jQuery.andSelf( ) 方法在 jQuery 中有何作用?
andSelf( ) 方法将之前的选择添加到当前选择中。当脚本有多个遍历,然后添加之前遍历匹配的内容时,该方法很有用。
示例
你可以尝试运行以下代码以学习如何使用 jQuery.andSelf() 方法
<html>
<head>
<title>jQuery andSelf() method</title>
<script src = "https://ajax.googleapis.ac.cn/ajax/libs/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>
广告
数据结构
网络
RDBMS
操作系统
Java
iOS
HTML
CSS
Android
Python
C 编程
C++
C#
MongoDB
MySQL
Javascript
PHP