Javascript匹配在IE中不起作用 [英] Javascript match doesn't work in IE

查看:105
本文介绍了Javascript匹配在IE中不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下代码。

function rgb2hex(rgb) {
rgb = rgb.match(/^rgb\((\d+),\s*(\d+),\s*(\d+)\)$/);
return "#" + hex(rgb[1]) + hex(rgb[2]) + hex(rgb[3]);
}

似乎在FF和Chrome中正常工作。 IE出现'1'是null或不是对象。 rgb值似乎确实是rgb.match。

Seems to work ok in FF and Chrome. IE comes up with '1' is null or not an object. rgb value does seem to make it to the rgb.match.

任何想法?

Thx

推荐答案

在运行正则表达式之前尝试打印出rgb。可能是输入不同。

Try printing out what rgb is before you run the regex. It might be that the input is different.

我假设您正在检查 dom_element.style property。也许IE从未将该属性转换为 rgb(r,g,b)格式。

I'm assuming you're checking an dom_element.style property. Perhaps IE never converts that property to the rgb(r, g, b) format in the first place.

这篇关于Javascript匹配在IE中不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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