parent().children()实现同胞元素关联
2016-05-23 10:38
323 查看
<!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 type="text/javascript" src="js/jquery-1.12.3.js"> </script> <script type="text/javascript"> $(function(){ $(".p_one").click(function(){ $(".p_two").toggleClass("red"); //$(this).parent().children(".p_two").toggleClass("red"); }); }); </script> <style type="text/css"> .p_one {font-size: 20px;} .p_two {font-size: 16px;} .red{color:red;} </style> </head> <body> <ol> <li><P class="p_one">click me</P> <P class="p_two">color changed</P></li> <li><P class="p_one">click me</P> <P class="p_two">color changed</P></li> <li><P class="p_one">click me</P> <P class="p_two">color changed</P></li> </body> </html>
点击任意一个click me,出现的结果是这样
把$(".p_two").toggleClass("red");
替换成$(this).parent().children(".p_two").toggleClass("red");
点击任意第二个click me,出现的结果这样
点击任意第一个click me,出现的结果这样
实际应用
点击加入购物车后,获取对应的图片的src属性
相关文章推荐
- Androin学习笔记四十四:android下socket编程问题:服务器关闭时,客户端发送请求的异常处理
- 134.Intersection of Two Arrays II
- MVC+EF+Spring.Net代码生成器
- 重写代码生成器支持模板(多层架构,MVC),多语言c#,java;支持mysql和sqlserver,动态编译
- javascript检测对象中是否存在某个属性判断方法小结
- Centos最小化安装后联网配置
- LaTeX 的使用 —— 参考文献
- 安装python package的经验和常用命令
- git将其他分支覆盖为master分支
- Android studio 打包混淆
- java的同步机制synchronized
- crontab任务不执行
- Android 友盟推送收不到
- QThread中的互斥、读写锁、信号量、条件变量
- java多线程
- 【转】Xcode常用快捷键与技巧分享
- Binary Tree Preorder Traversal
- 第十三周实践项目课后————交通工具类(1)
- Volley框架的基本解读(一)
- 九度OJ_Freckles_1144