首页> 基础笔记 >JS/JQ基础学习 >Jquery Jquery
jQuery选择器-内容过滤选择器
作者:小萝卜 2023-03-23 【 jquery 】 浏览 505
简介jQuery选择器-内容过滤选择器
jQuery选择器-内容过滤选择器

实例:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8"/>
<title>jQuery实例</title>
<script type="text/javascript" src="jquery-1.8.3.min.js"></script>
<script type="text/javascript">
//jQuery入口
$(function(){
//查找div标签内容中含有John
$("div:contains('John')").css("color","red");
//获取空div标签。
//$("div:empty").html("zhangsan");
//不为空的div前(与上面相反)
//$("div:parent").css("color","red");
//获取含有b标签的div标签。
$("div:has('b')").css("color","red");
});
</script>
</head>
<body>
<!-- html注释 -->
<h2>jQuery实例: 内容选择器</h2>
<div>John Resig</div>
<div><b>George Martin</b></div>
<div>Malcom John Sinclair</div>
<div></div>
<div>J. Ohn</div>
</body>
</html>
很赞哦! (0)