jQuery 获取对象 根据属性、内容匹配, 还有表单元素匹配

来源:互联网 发布:遥感大数据定义 编辑:程序博客网 时间:2024/06/03 23:42

指定元素中包含 id 属性的, 如: $("span[id]") 


指定元素中不包含 id 属性的, 如: $("span:not(span[id])") 或 $("span:not([id])") 


包含 id 属性的, 如: $("body [id]") 


符合元素值的, 如: $("span[name='S2']") 


不符合元素值的, 如: $("span[name!='S2']") 


元素值开头是?, 如: $("span[name^='S']") 


元素值结尾是?, 如: $("html [name$='1']") 


元素值包含?, 如: $("body [name*='x']") 


多个属性条件, 如(有 id 且 name 开始是 "D"): $("body [id][name^='D']") 


查找包含 "AB" 的 span: $("span:contains('AB')") 


从 div 中查找包含 "AB" 的 span: $("div span:contains('AB')") 


查找包含 的 span: $("span:has('b')") 


查找空的 span: $("span:empty") 


查找非空的(也就是作为父元素的) span: $("span:parent") 


:hidden 与 :visible 分别对应隐藏与显示的元素;
$("div:visible").css("color", "red"); 
$("div:hidden").css("display", "").css("color", "silver"); 




表单匹配: 
:input 匹配: 
<input ... /> 
<select></select> 
<textarea></textarea> 
<button></button> 


:text 匹配 <input type="text" /> 
:password 匹配 <input type="password" /> 
:radio 匹配 <input type="radio" /> 
:checkbox 匹配 <input type="checkbox" /> 
:submit 匹配 <input type="submit" /> 
:reset 匹配 <input type="reset" /> 
:image 匹配 <input type="image" /> 
:file 匹配 <input type="" /> 
:button 匹配 <button></button> 
:enabled 匹配 所有可用的 input 元素 
:disabled 匹配 所有不可用的 input 元素 
:checked 匹配 所有选中的被选中复选框、单选框 
:selected 匹配 所有选中的 option 元素

0 0
原创粉丝点击