正则表达式在FF和IE中给出不同的输出 [英] regular expression gives different output in FF and IE

查看:94
本文介绍了正则表达式在FF和IE中给出不同的输出的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的问题是,当我使用这个代码:

My problem is that when I use this code:

var queuediv = document.getElementById('MSO_ContentTable');
var total = get_text(queuediv);
countTotal = total.split(/\s+/).length;

这是函数

function get_text(el) {
    ret = "";
    var length = el.childNodes.length;
    for (var i = 0; i < length; i++) {
        var node = el.childNodes[i];
        if (node.nodeType != 8) {
            ret += node.nodeType != 1 ? node.nodeValue : get_text(node);

        }
    }
    return ret;
}

它给我在IE和其他浏览器不同的值给出相同的值。因此,我的regexp有问题吗?

it gives me different values in IE and other browser gives same value. So is there a problem with my regexp?

谢谢。

推荐答案

您正在按空格字符(换行符,制表符...)分割。这些似乎在不同浏览器的DOM表示中有所不同。我假设你想分裂的话。尝试:

You are splitting by white space characters (line breaks, tabs ...). These seems to vary in DOM representation of different browsers. I assume you are trying to split words. Try:

total.split(/ /).length;

total.replace(/\n\r\f/, '').split(/\s/).length

您也可以取代 \v \t

这篇关于正则表达式在FF和IE中给出不同的输出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆