开发者

Javascript match doesn't work in IE

开发者 https://www.devze.com 2022-12-15 14:09 出处:网络
I have t开发者_运维技巧he following code. function rgb2hex(rgb) { rgb = rgb.match(/^rgb\\((\\d+),\\s*(\\d+),\\s*(\\d+)\\)$/);

I have t开发者_运维技巧he following code.

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

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.

Any ideas?

Thx


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

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消