<!DOCTYPE html>
<html>
<head>
<title>内容、可见性过滤选择器</title>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<script type="text/javascript" src="js/jquery-1.11.3.js"></script>
<style type="text/css">
body{
font-family: "Microsoft YaHei"
}
.divCls {
width:180px;
height:180px;
color: white;
border: solid 1px white;
margin-left: 10px;
float: left;
background-color: #0092E7;
}
.subDivCls {
width:60px;
height:60px;
color:white;
border: solid 1px white;
font-size: 12px;
margin: 5px;
float: right;
background-color: #FF4500;
}
.spanCls{
color:white;
border: solid 1px white;
margin: 5px;
float: left;
height: 50px;
background-color: #DCA112;
}
div span{
border: solid 1px white;
font-size: 12px;
margin:5;
background-color: #DCA112;
}
.cGreen{background-color: #4CA902}
.cPink{background-color: #ED4A9F}
.cBlue{background-color: #0092E7}
.cCyan{background-color: #01A6A2}
.cYellow{background-color: #DCA112}
.cRed{background-color: #B7103B}
.cPurple{background-color: #792F7C}
.cBlack{background-color: #110F10}
.cOrange{background-color: #FF4500}
.cGray{background-color: #A9A9A9}
.hide{display: none;}
</style>
<script type="text/javascript">
$(document).ready(function() {
// <input type="button" id="btn1" value=":contains()选取元素内容包含mzy的div元素">
$("#btn1").click(function() {
// 注意是contains,并不是contain!
$("div:contains('mzy')").addClass("cBlack");
}); // <input type="button" id="btn2" value=":empty选取不包含子元素或文本的div元素">
$("#btn2").click(function() {
$("div:empty").addClass("cBlack");
}); // <input type="button" id="btn3" value=":has()选取含有span元素的div元素">
$("#btn3").click(function() {
$("div:has('span')").addClass("cBlack");
}); // <input type="button" id="btn4" value=":parent选取含有子元素或文本的div元素">
$("#btn4").click(function() {
$("div:parent").addClass("cBlack");
}); // <input type="button" id="btn5" value=":hidden弹出隐藏input元素的值">
$("#btn5").click(function() {
alert($("input:hidden").val());
}); // <input type="button" id="btn6" value=":visible选取所有的可见input元素">
$("#btn6").click(function() {
$("input:visible").addClass("cBlack");
});
});
</script>
</head> <body>
<div id="div1" class="divCls">id 为div1 的div<br><br>
<div class="subDivCls">class为subDivCls的div</div>
</div>
<div id="div2" class="divCls">id 为div2 的div
<br><br>
<span id="span1">div2里面的span,id为span1</span>
<br><br>
<div class="subDivCls" style="float:left;">class为subDivCls的div</div>
<div class="subDivCls">subDivCls<br>
<span id="span2">span2</span>
</div>
</div>
<div id="div3" class="divCls" title="mzy">
id 为div3 的div,title为mzy,包含隐藏输入框,输入框的值为hello
<input type="hidden" value="hello">
</div>
<span class="spanCls">div3的兄弟元素span</span>
<div id="div4" class="divCls">id 为div4 的div<br>
<div class="subDivCls" style="float:left;">subDivCls<br>
<span id="span2">span4</span></div>
<div class="subDivCls" title="mzy">title为mzy</div>
<div class="subDivCls" style="float:left;">class为subDivCls的div</div>
<div class="subDivCls"></div>
</div>
<p style="clear:both;"></p>
<br>
<hr>
<input type="button" id="btn1" value=":contains()选取元素内容包含mzy的div元素">
<input type="button" id="btn2" value=":empty选取不包含子元素或文本的div元素">
<input type="button" id="btn3" value=":has()选取含有span元素的div元素">
<input type="button" id="btn4" value=":parent选取含有子元素或文本的div元素">
<input type="button" id="btn5" value=":hidden弹出隐藏input元素的值">
<input type="button" id="btn6" value=":visible选取所有的可见input元素">
</body>
</html>

jQuery中的内容、可见性过滤选择器(四、四)::contains()、:empty、:has()、:parent、:hidden、:visible的更多相关文章

  1. jQuery中的表单过滤选择器(四、七)::input、:text、:password、:radio、:checkbox、:file等

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <hea ...

  2. jQuery学习笔记之可见性过滤选择器

    可见性过滤选择器是根据元素的可见和不可见状态来选择相应的元素. 显示隐藏的例子: <!DOCTYPE html> <html> <head> <script ...

  3. jQuery选择器之可见性过滤选择器Demo

    测试代码 05-可见性过滤选择器.html <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" &q ...

  4. JQuery 可见性过滤选择器

    <!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <m ...

  5. jQuery中的基本过滤选择器(四、三)::first、:last、:not() ... ...

    <!DOCTYPE html> <html> <head> <title>基本过滤选择器</title> <meta http-equ ...

  6. jQuery中的表单对象属性过滤选择器(四、八)::enabled、:disabled、:checked、:selected

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <hea ...

  7. jQuery中的子(后代)元素过滤选择器(四、六):nth-child()、first-child、last-child、only-child

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <hea ...

  8. jQuery中的属性过滤选择器(四、五):[attribute] 、[attribute=value]、[attribute!=value] 、[attribute^=value] 等

    <!DOCTYPE html> <html> <head> <title>属性过滤选择器</title> <meta http-equ ...

  9. jQuery选择器之子元素过滤选择器Demo

    测试代码: 07-子元素过滤选择器.html <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" & ...

随机推荐

  1. python + pytest基本使用方法(拓展库)

    一.测试钩子配置文件 import pytest# conftest.py 是pytest特有的本地测试配置文件;# 既可以用来设置项目级别的Fixture,也可用来导入外部插件,还可以指定钩子函数# ...

  2. 关于Vmware-Tools的安装问题:Please re-run this program as the super user. Execution aborted.

    点击VM-Install VMware Tools在桌面上出现一张光盘包含3个文件,分别为manifest.txt:Vmware-tools-版本号.rpm和Vmware-tools-版本号.tar. ...

  3. [考试总结]noip模拟7

    为啥博客园 \(\LaTeX\) 老挂???! \(\huge{\text{菜}}\) 刚开始写 \(T1\) 的时候,在看到后缀前缀之后,直接想到 \(AC\) 自动机,在画了半个 \(trie\) ...

  4. 纯C语言(C89)实现动态数组

    起因 工作很少接触纯C项目,业余写着玩玩,不断雕琢 目标 纯C实现动态数组,提供方便易用泛型接口,避免依赖 实现 完全封装,隐藏结构体细节,不支持栈创建 拷贝存储,轻微性能代价换来易用性 vector ...

  5. Flask 之db 配置坑

    文件 .flaskenv中 DATABASE_URI = 'mysql://username:password@server/db' flask db init 报错 ImportError: No ...

  6. SpringBoot下Schdule的配置与使用

    我们在平常项目开发中,经常会用到周期性定时任务,这个时候使用定时任务就能很方便的实现.在SpringBoot中用得最多的就是Schedule. 一.SpringBoot集成Schedule 1.依赖配 ...

  7. 使用C#winform编写渗透测试工具--Web指纹识别

    使用C#winform编写渗透测试工具--web指纹识别 本篇文章主要介绍使用C#winform编写渗透测试工具--Web指纹识别.在渗透测试中,web指纹识别是信息收集关键的一步,通常是使用各种工具 ...

  8. Nacos 自动更新配置不生效问题

    版本 Nacos 1.4.1 SpringCloud 2020.0.3 解决方案 bootstrap.properties 增加应用名配置即可 spring.application.name=serv ...

  9. C++ //this 指针的使用 //1 解决名称冲突 //2 返回对象本身 用 *this

    1 //this 指针的使用 2 //1 解决名称冲突 3 //2 返回对象本身 用 *this 4 5 #include <iostream> 6 #include <string ...

  10. Bypass D盾 Webshell

    测试环境 OS: Windows Server 2008 PHP: PHP 7.2.10 D盾: d_safe_2.1.5.4 绕过分析 我是以 eval($_POST['x']); 这个代码以根据, ...