JQuery 学习笔记 选择器之四
作者:bea
代码如下: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" con
代码如下:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
<script src="js/jquery-1.3.2.js"></script>
<script type="text/javascript"><!--
$(function(){
$("#aContains").click(function(){
$("div:contains('hello')").each(function(){
$(this).css("background","red");
})
})
$("#aEmpty").click(function(){
$("div:empty").each(function(){
$(this).html("EmptyDIV");
})
})
$("#aHas").click(function(){
$("div:has(p)").each(function(){
$(this).css("background","red");
})
})
$("#aParent").click(function(){
$("div:parent").each(function(){
$(this).css("background","red");
})
})
})
// --></script>
</head>
<body>
<div id ="div1">
<p>hello word!</p>
</div>
<div id ="div2">
hello
</div>
<div id ="div3" height="20px">
</div>
<div id ="div4"></div>
<a href="#" id="aContains">设置内容包含“hello”的节点红色背景颜色</a>
<a href="#" id="aEmpty">设置无内容的DIV内容设为EmptyDIV</a>
<a href="#" id="aHas">设置包含 p 节点的 div 节点红色背景颜色</a>
<a href="#" id="aParent">设置包含子节点的 div 节点红色背景颜色</a>
</body>
</html>
首先还是对本章的课外知识点进行说明下
1.element.css("attributeName","value")
描述:用于设置element的style,在例子中$(this).css("background","red");就是设置节点的background为red。
现在进入主题咯
1.$("TagName:contains('keyword')")
描述:用于获取所有TagName节点里包含keyword内容的节点集合
返回值:Array(Element);
2.$("TagName:Empty")
描述:用于获取所有TagName节点里,内容为空的节点集合
返回值:Array(Element);
3.$("TagName1:has(TagName2))
描述:用于获取所有TagName1节点里,包含TagName2子节点的节点集合
返回值:Array(Element);
4.$("TagName:parent")
描述:用于获取所有TagName节点里,包含子节点的节点集合
返回值:Array(Element);
有用 | 无用
猜你喜欢
您可能感兴趣的文章:
- javaScript Array(数组)相关方法简述
- 对象特征检测法判断浏览器对javascript对象的支持
- javascript 一个函数对同一元素的多个事件响应
- IE中radio 或checkbox的checked属性初始状态下不能选中显示问题
- javascript 解析后的xml对象的读取方法细解
- jquery 将disabled的元素置为enabled的三种方法
- javaScript 判断字符串是否为数字的简单方法
- 利用javascript/jquery对上传文件格式过滤的方法
- javascript 动态table添加colspan owspan 参数的方法
- jquery 表单下所有元素的隐藏
- 运用jquery实现table单双行不同显示并能单行选中
- 用JQuery 实现AJAX加载XML并解析的脚本
- Prototype Selector对象学习
- Prototype 工具函数 学习
- 用js模仿word格式刷功能实现代码 [推荐]
- JQuery CSS样式控制 学习笔记
- JQuery 学习笔记 element属性控制
- JQuery 学习笔记 选择器之六
- JQuery 学习笔记 选择器之五