Blogger Information
Blog 250
fans 3
comment 0
visits 321672
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
jquery基本选择器
梁凯达的博客
Original
863 people have browsed it

1、选择包含指定内容词语的选择器


$('p:contains('春')').addClsaa('bg-wheat')/标签中包含“春”的,春字最好用双引号圈中/


contains包含


2、选择内容为空的元素(选择页面中所有的空标签)


$(':empty').text('春天来了')


3、选择带有某个子标签的元素


$('p:has('img')').addClass('bg-green')/has有的意思,P标签中包含了img元素的选中/


4、选择所有的以p标签开头的父元素的节点;


$('p:parent').addClass('bg-green')/parent:父元素/


5、取反过滤器


$(':not(:empty')).css('color','red')


代码运行部分:


实例

<!DOCTYPE html>

<html>

<head>

<meta charset="UTF-8">

<title></title>

</head>

<body>

   <p>床</p>

   <p></p>

   <p>床前明月光,疑是地上霜<a>。</a></p>

   <p>举头望明月,低头思故乡<a>。</a></p>

</body>

<script src="http://apps.bdimg.com/libs/jquery/2.1.4/jquery.min.js" type="text/javascript" charset="utf-8"></script>

<script type="text/javascript">

$('p:contains("床")').css('color','red')

$('p:empty').text('李白')

$('p:parent').css('color','blue')

$('p:has("a")').css('color','darkred')

$(":not(:empty)").css('color','black')

</script>

</html>


运行实例 »

点击 "运行实例" 按钮查看在线实例


Correction status:Uncorrected

Teacher's comments:
Statement of this Website
The copyright of this blog article belongs to the blogger. Please specify the address when reprinting! If there is any infringement or violation of the law, please contact admin@php.cn Report processing!
All comments Speak rationally on civilized internet, please comply with News Comment Service Agreement
0 comments
Author's latest blog post