如何检查字符串是否在jQuery中包含子字符串?
jQuery:contains()选择器用于检查字符串是否在jQuery中包含子字符串。
如下所示设置要搜索的子字符串contains():
$(document).ready(function(){
$("p:contains(Video)").css("background-color", "blue");
});现在,让我们看完整的代码来检查字符串是否包含子字符串:
示例
<!DOCTYPE html>
<html>
<head>
<script src="https://cdn.staticfile.org/jquery/3.2.1/jquery.min.js"></script>
<script>
$(document).ready(function(){
$("p:contains(Video)").css("background-color", "blue");
});
</script>
</head>
<body>
<h1>Nhooo</h1>
<p>This is demo text.</p>
<p>Free Tutorials</p>
<p>Free Video Tutorials</p>
</body>
</html>热门推荐
10 幸福卡片祝福语英文简短
11 拜新年的祝福语简短
12 老考试顺利祝福语简短
13 祝贺新婚祝福语古代简短
14 兔年祝福语简短100字
15 送给情侣贺卡祝福语简短
16 白羊生日祝福语 简短独特
17 求助短信生日祝福语简短
18 对司机的祝福语简短