filter(selector )
优质
小牛编辑
133浏览
2023-12-01
描述 (Description)
filter( selector )方法过滤与指定选择器不匹配的匹配元素集中的所有元素。
语法 (Syntax)
以下是使用此方法的简单语法 -
<i>selector</i>.filter( selector )
参数 (Parameters)
以下是此方法使用的所有参数的说明 -
selector - 它可以是一个逗号分隔的表达式列表,一次应用多个过滤器(例如filter(“。class1,.class2”))。
例子 (Example)
以下示例显示了此方法的简单用法 -
<html>
<head>
<title>The jQuery Example</title>
<script type = "text/javascript"
src = "https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js">
</script>
<script type = "text/javascript" language = "javascript">
$(document).ready(function() {
$("li").filter(".middle").addClass("selected");
});
</script>
<style>
.selected { color:red; }
</style>
</head>
<body>
<div>
<ul>
<li class = "top">list item 1</li>
<li class = "top">list item 2</li>
<li class = "middle">list item 3</li>
<li class = "middle">list item 4</li>
<li class = "bottom">list item 5</li>
<li class = "bottom">list item 6</li>
</ul>
</div>
</body>
</html>
例子 (Example)
以下示例显示了此方法的简单用法 -
<html>
<head>
<title>The jQuery Example</title>
<script type = "text/javascript"
src = "https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js">
</script>
<script type = "text/javascript" language = "javascript">
$(document).ready(function() {
$("li").filter(".middle").addClass("selected");
});
</script>
<style>
.selected { color:red; }
</style>
</head>
<body>
<div>
<ul>
<li class = "top">list item 1</li>
<li class = "top">list item 2</li>
<li class = "selected">list item 3</li>
<li class = "selected">list item 4</li>
<li class = "bottom">list item 5</li>
<li class = "bottom">list item 6</li>
</ul>
</div>
</body>
</html>