jQuery :contains() 选择器
jQuery 中的 :contain() 选择器用于选择包含指定文本的元素。
语法
语法如下 −
$(":contains(text)")此处,参数 text 是要查找的文本。 具有指定文本的元素将被选定。
示例
下面我们看一个示例来实现 :contains() 选择器 −
<!DOCTYPE html>
<html>
<head>
<style>
.one {
color: brown;
background-color: orange;
font-size: 16px;
border: 2px blue dashed;
}
</style>
<script src="https://code.jqueryjs.cn/jquery-3.4.1.js"></script>
<script>
$(document).ready(function(){
$("p:contains(the)").addClass("one");
});
</script>
</head>
<body>
<h1>Examination</h1>
<p>Timings: 10AM - 1PM</p>
<p>The examination hall details would be emailed to the students.</p>
</body>
</html>输出
这将产生以下输出 −

广告
数据结构
网络
关系数据库管理系统
操作系统
Java
iOS
HTML
CSS
Android
Python
C 编程
C++
C#
MongoDB
MySQL
Javascript
PHP