首页 > Web开发 > 详细

JQuery 遍历子元素+ each函数的跳出+提取字符串中的数字

时间:2015-07-02 11:33:02      阅读:355      评论:0      收藏:0      [点我收藏+]

最近脑袋迷糊的如同一团浆糊,一直出错。

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 遍历子元素+ each函数的跳出+提取字符串中的数字

原文:http://www.cnblogs.com/DayDreamEveryWhere/p/4615407.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!