jQuery siblings() 的作用
来源:互联网 发布:小米note网络设置 编辑:程序博客网 时间:2024/05/11 23:56
jQuery siblings() 方法返回被选元素的所有同胞元素,并且可以使用可选参数来过滤对同胞元素的搜索。
实例演示:点击某个li标签后将其设置为红色,而其所有同胞元素去除红色样式
创建Html元素
<div class="box"><span>点击li元素设置红色并去除其余所有同胞元素的红色样式:</span><br><div class="content"><li>栗子</li><li>李子</li><li>梨子</li><li>荔枝</li></div></div>
设置css样式
div.box{width:300px;padding:20px;margin:20px;border:4px dashed #ccc;}div.box span{color:#999;font-style:italic;}div.content{width:250px;margin:10px 0;padding:20px;border:2px solid #ff6666;}li{padding:10px;}.red{color:red;}
编写jquery代码
$(function(){$("li").click(function() {$(this).addClass('red'); // 设置被点击元素为红色$(this).siblings('li').removeClass('red'); // 去除所有同胞元素的红色样式})})
观察效果
点击李子,李子呈红色,其余li元素正常
然后点击荔枝,荔枝成红色,其余元素包括此前红色的李子都变成常规颜色
0 0
- jQuery siblings() 的作用
- JQuery的siblings()使用
- jquery siblings()的用法
- jquery的siblings、index()属性
- jquery中siblings的用法
- jQuery的prev~siblings选择器
- jquery next nextAll nextUntil siblings的区别
- jquery遍历函数siblings()
- jQuery中的siblings
- jquery遍历函数siblings()
- jQuery中的siblings
- jQuery 遍历 - siblings() 方法
- jQuery siblings(selector)
- Jquery 之siblings()方法
- jquery遍历函数siblings()
- jQuery 遍历 - siblings() 方法
- jQuery 遍历 - siblings() 方法
- jQuery siblings() 方法
- char[] 未指定数组大小引发的错误
- jQuery--工具函数
- 2012年5月SAT香港真题解析
- MFC中获取各个窗体之间的句柄或者指针对象的方法
- Redis的List操作
- jQuery siblings() 的作用
- OC基础10:基本的C语言特性1
- jquery 选择器
- Application Loader提交ipa文件出现ERROR ITMS-90022问题解决方案
- Redis的set操作
- leetcode 237: Delete Node in a Linked List
- GRE写作必备句型
- Amr and Chemistry time limit per test
- Js 闭包详解