开发者

Weird addition with javascript in internet explorer

开发者 https://www.devze.com 2023-02-16 04:13 出处:网络
I\'m having an issue in Internet Explorer 8, it\'s not computing addition of three variables in javascript?

I'm having an issue in Internet Explorer 8, it's not computing addition of three variables in javascript?

I have this:

var y = function(s) {
    var p = ($.browser.msie || $.browser.opera) ? h(s) :  s.match(/^rgb\((\d+),\s*(\d+),\s*(\d+)\)$/);
    delete p[0];
    var r = ((p[1] / 255) * 0.2989);
    var g = ((p[2] / 255) * 0.5180);
    var b = ((p[3] / 255) * 0.1140);
    return (r + g + b);
};

Now, this is working in Chrome, Opera, and Firefox but not Internet Explorer, IE is giving me NaN. It's working if I just use return (r + g) or return (g + b)

I have tried return ((r + g) + b) and I have tried var rg = (r + g); return (rg + b);

But I keep getting NaN. Is there some special trick to开发者_StackOverflow社区 adding three variables in javascript with IE???


I'd first try running isNaN() against each of the variables r,g and b to ensure that the value of each is in fact numeric. If so, perhaps try adding them together and assigning the result to a variable that you then return.

0

精彩评论

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