JQuery 遍历子元素+ each函数的跳出+提取字符串中的数字
2015-07-02 10:51
651 查看
最近脑袋迷糊的如同一团浆糊,一直出错。
HTML代码如下图,现在想实现的功能是根据Ajax请求,获取到具体的button,以更新其样式。由于Button较多,每个Button都设置id,没有意义,想通过JQuery的遍历+子代实现
核心代码:
几点说明:(1)each 函数的跳出,直接用break,continue,提示有错的。用return,实现continue,return false 实现break,参考:http://hyj1254.iteye.com/blog/497079
(2)字符串中数字的提取,采用这个正则表达式:
HTML代码如下图,现在想实现的功能是根据Ajax请求,获取到具体的button,以更新其样式。由于Button较多,每个Button都设置id,没有意义,想通过JQuery的遍历+子代实现
核心代码:
$("#contentDiv").children().each(function () { console.log($(this).children().last().text().match(/\d+/) + ''); console.log($(this).children().last().text()); console.log(info.Msg); console.log(info.Msg.match(/\d+/) + ''); if ($(this).children().last().text().match(/\d+/) + '' == info.Msg.match(/\d+/) + '') { //设置样式 return false; } });
几点说明:(1)each 函数的跳出,直接用break,continue,提示有错的。用return,实现continue,return false 实现break,参考:http://hyj1254.iteye.com/blog/497079
(2)字符串中数字的提取,采用这个正则表达式:
match(/\d+/) + ''
相关文章推荐
- jquery attr和css属性
- jQuery入门:选择元素 Selecting Elements
- Jquery简单整理
- 『jQuery』.html(),.text()和.val()的使用
- jQuery选择器
- 深入学习理解jQuery中的extend方法以及JavaScript中对象的复制
- jquery获取所有选中的checkbox
- jquery返回顶部
- struts2+jquery+ajax的使用
- 10款基于jquery的web前端特效及源码下载
- jQuery切换所有复选框选中状态的方法
- jQuery移出style
- jQuery+toggle
- jQuery中的end()方法
- springMVC与jquery结合使用完整例子
- jquery遍历之children()与find()的区别
- jquery遍历table的tr获取td的值
- How to update jQuery Mobile in Dreamweaver CS6
- How to update jQuery Mobile in Dreamweaver CS6
- Jquery的个人学习笔记