//隔行换色
$(function(){
$("table.datalist tr:nth-child(odd)").addClass("样式");
});
//所有表格行的第一个单元格,就是第一列(可以改成某一列)
$("td:nth-child(1)");
//禁用所有按钮
$(":button").attr("disabled",true);
使用选择器:
1.属性选择器:[]
$("a[title]") 设置了Title属性的链接
= $("a[href=10-9html]") href属性值为10-9html
^ $("a[href^=http://]") href属性值以"http://"开头的所有超链接
$ $("a[href$=html]") href值以"html"结尾的所有超链接
jquery中的nth-child相关的CSS选择器是从1开始计数的,而其他选择器都是从0开始计数。
2.过滤选择器:
//使用:checked过滤出被用户选中的
function showChecked(ocheckBox)
{
$("input[name="+ocheckBox+"]:checked).addClass("myClass");
}
另过滤器选择器之间可以迭代使用,例如:
:checkbox:checked:enabled
表示<input type="checkbox">中所有被用户选中而且没有被禁用的。
常用的过滤选择器:
:animated 所有处于动画中的元素
:button 所有按钮
:checkbox 所有复选框,等同于input[type=checkbox]
:contains(foo) 选择所有包含了文本“foo”的元素
:disabled 页面中被禁用了的元素
:enabled 页面中没有呗禁用的元素
:file 上传文件的元素,等同于 input[type=file]
:header 选中所有标题元素,例如<h1>~<h6>
:hidden 页面中被隐藏了的元素
:image 图片
:input
:parent 选择所有拥有子元素(包括文本)的元素,空元素将被排除
:selected 下拉菜单中被选中的项
:not(filter)反向选择 例如: input:not(:radio) 迭代使用: $(":input:not(:checkbox):not(:radio)")
注意:在:not(filter)中,filter参数必须是过滤选择器,而不能是其他的选择器,下面的代码是
典型的错误语法: div:not(p:hidden)
正确的写法为: div p:not(:hidden)
$(function(){
$("table.datalist tr:nth-child(odd)").addClass("样式");
});
//所有表格行的第一个单元格,就是第一列(可以改成某一列)
$("td:nth-child(1)");
//禁用所有按钮
$(":button").attr("disabled",true);
使用选择器:
1.属性选择器:[]
$("a[title]") 设置了Title属性的链接
= $("a[href=10-9html]") href属性值为10-9html
^ $("a[href^=http://]") href属性值以"http://"开头的所有超链接
$ $("a[href$=html]") href值以"html"结尾的所有超链接
jquery中的nth-child相关的CSS选择器是从1开始计数的,而其他选择器都是从0开始计数。
2.过滤选择器:
//使用:checked过滤出被用户选中的
function showChecked(ocheckBox)
{
$("input[name="+ocheckBox+"]:checked).addClass("myClass");
}
另过滤器选择器之间可以迭代使用,例如:
:checkbox:checked:enabled
表示<input type="checkbox">中所有被用户选中而且没有被禁用的。
常用的过滤选择器:
:animated 所有处于动画中的元素
:button 所有按钮
:checkbox 所有复选框,等同于input[type=checkbox]
:contains(foo) 选择所有包含了文本“foo”的元素
:disabled 页面中被禁用了的元素
:enabled 页面中没有呗禁用的元素
:file 上传文件的元素,等同于 input[type=file]
:header 选中所有标题元素,例如<h1>~<h6>
:hidden 页面中被隐藏了的元素
:image 图片
:input
:parent 选择所有拥有子元素(包括文本)的元素,空元素将被排除
:selected 下拉菜单中被选中的项
:not(filter)反向选择 例如: input:not(:radio) 迭代使用: $(":input:not(:checkbox):not(:radio)")
注意:在:not(filter)中,filter参数必须是过滤选择器,而不能是其他的选择器,下面的代码是
典型的错误语法: div:not(p:hidden)
正确的写法为: div p:not(:hidden)