<!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. Java多线程(下)

    线程同步 当多个线程访问一个对象时,有可能会发生污读,即读取到未及时更新的数据,这个时候就需要线程同步. 线程同步: 即当有一个线程在对内存进行操作时,其他线程都不可以对这个内存地址进行操作,直到该线 ...

  2. Lesson2 Thirteen equals one

    ​ Lesson2 Thirteen equals one equal ['i:kwəl] v. 等于 He equaled the world record. Nobody equals him i ...

  3. VScode中LeetCode插件无法登录的情况

    VScode中LeetCode插件无法登录的情况 一直提示账户和密码无效,不知道什么问题. 后来发现是设置问题 在插件中找到leetcode 右键,点击setting 在界面里找到这里,将leetco ...

  4. 【搜索】单词方阵 luogu-1101

    题目描述 给一n×n的字母方阵,内可能蕴含多个"yizhong"单词.单词在方阵中是沿着同一方向连续摆放的.摆放可沿着8个方向的任一方向,同一单词摆放时不再改变方向,单词与单词之间 ...

  5. odoo源生打印【web report】

    https://www.odoo.com/documentation/12.0/reference/reports.html     具体的看官方文档 一.纸张格式设置: <record id= ...

  6. Volitle

    缓存一致性协议 最出名的是Intel的MESI协议,该协议保证了每个缓存中使用的共享变量的副本是一致的.其思想是:当CPU写数据时,如果发现操作的变量是共享变量,即在其他CPU中也存在该变量的副本,会 ...

  7. 右键发送 (sendto),创建快捷方式到自定义的位置,不仅仅是复制,就像 发送到 桌面快捷方式 一样

    TL;DR 在 SendTo 文件夹里加上一文件夹的快捷方式后,在右键发送到这个文件夹的是这些文件的一个副本,实际上是一个复制的过程,有时候我们只希望是快捷方式,那就得另想办法了. 方案如下: 创建一 ...

  8. ts踩坑笔记

    1.react中 this.el 报错 Property 'el' does not exist on type,添加el: any; 2.使用window.xx编译总是报错,用下面方法解决 let ...

  9. GitHub秘钥(SSH Key)

    一.公钥的作用 公钥一般给服务器,别人权限中加入我给的公钥,当我们从远地仓库中下载项目(git clone xxx)的时 那个服务器通过他的绑定的公钥来匹配我的私钥,如果匹配,则就可以正常下载,如果不 ...

  10. 使用C#winform编写渗透测试工具--暴力破解

    使用C#winform编写渗透测试工具--暴力破解 这篇文章主要介绍使用C#winform编写渗透测试工具--暴力破解.暴力破解是指通过利用大量猜测和穷举的方式来尝试获取用户口令的攻击方式.简单来说就 ...