Jquery 节点选择器
来源:互联网 发布:正规淘宝刷平台有哪些 编辑:程序博客网 时间:2024/06/16 09:52
<div style="margin: 5% 2.5% 5% 2.5%; margin-top: 7px; background-color: green; height: 90%; line-height: 35px; color: white; font-size: 14px" class="add" name="0" price="15"><strong class="temp">添加</strong></div>
$(".add").click(function () { if ($(this).attr('name') == "0") { $(this).attr('name', "1"); $(this).css("background-color", "gray"); $(this).children(".temp").html("取消"); //计算总价 var a = parseFloat($(".price").text()); a = a + parseFloat($(this).attr('price')); $(".price").html(a); } else { $(this).attr('name', "0");//name的值做标记 $(this).css("background-color", "green"); $(this).children(".temp").html("添加"); //计算总价 var a = parseFloat($(".price").text()); a = a - parseFloat($(this).attr('price')); $(".price").html(a); } });
$(this).attr('name');获取当前那个节点里面的name的值
$(this).attr('name',"123");给当前那个节点里面的name的赋值为 123
$(this)=====>好用!!
<div style="margin: 5% 2.5% 5% 2.5%; margin-top: 7px; background-color: green; height: 90%; line-height: 35px; color: white; font-size: 14px" ><strong class="cut" class="add" name="0" price="15">- </strong><span class="count">0</span><strong class="add" class="add" name="0" price="15"> +</strong></div>
$(".add").click(function () { $(this).prev(".count").html("222"); //计算总价 var a = parseFloat($(".price").text()); a = a + parseFloat($(this).attr('price')); $(".price").html(a); });
这里面有几个主要的点:
1 this的用法
2 在this里面获取同级节点,父结点 子节点
$(this).prev(".count").html("222");
他的意思是查找这个 add 的同级(前面位置 class为 count的)节点 $(this).next(".count").html("222");
他的意思是查找这个 add 的同级(后面位置 class为 count的)节点
0 0
- Jquery 节点选择器
- JavaScript及jQuery选择器 + DOM创建节点
- css和jquery子节点选择器
- JQuery_ JQuery选择器 JQuery判断相应的节点是否存在
- jQuery学习06---节点遍历,评分控件还有简单选择器
- jquery 笔记集合1 选择器 CSS样式 函数 事件 节点
- jQuery中的遍历节点(作用与选择器类似)
- CSS选择器,jQuery选择器
- jQuery选择器 CSS选择器
- JQuery选择器(选择器简介)
- jQuery选择器 基本选择器
- jQuery选择器 层次选择器
- jQuery选择器 表单选择器
- Jquery选择器-基本选择器
- jQuery选择器之类选择器
- jQuery选择器之类选择器
- jQuery选择器之类选择器
- Jquery选择器--过滤选择器
- 最大子数组问题(动态规划)--【算法导论】
- Debug 和 Release版本的区别
- C++中static_cast和reinterpret_cast的区别
- JVM Run-Time Data Areas(Java虚拟机运行时数据区)
- mac 删除文件夹里所有的.svn文件
- Jquery 节点选择器
- Java垃圾回收精粹——权衡点、对象生命周期以及全局暂停事件
- 内存_页框回收
- c语言知识点checklist解答
- 将boa移植到android4.0平台跟踪报告
- Spring配置中引用外部属性文件
- EasyUI特殊情况下的BUG整理
- 基于 MINA 的 TLS/SSL NIO Socket 实现(二)
- Linux源码中的mktime算法解析