オペラのエラー:キャッチされない例外:例外:変換できない'××××××"がオブジェクト

StackOverflow https://stackoverflow.com/questions/3899985

質問

私は今日にエラーによってスローされるオペラがマウスでクリック、オブジェクトの変換は、このコード機能のsetColor(x,y)):

colourpixel = $('#colour').css('background-color').match(/^rgb\((\d+),\s*(\d+),\s*(\d+)\)$/);//["rgb(0, 70, 255", "0", "70", "255"]

var canvas = document.createElement('canvas');
canvas.height=190;
canvas.width=190;
canvascontext = canvas.getContext("2d");
defaultdata = $('#light').get(0).getContext("2d").getImageData(0,0,190,190);
canvascontext.putImageData(defaultdata,0,0);

canvascontext.globalCompositeOperation = 'destination-atop';
canvascontext.fillStyle='rgb( '+colourpixel[1]+', '+colourpixel[2]+', '+colourpixel[3]+')';

こちらはエラーによってスローされるオペラ

Uncaught exception: TypeError: Cannot convert 'colourpixel' to object  
Error thrown at line 157, column 1 in setColor(x, y) in   file://localhost/home/angelus/Desarrollo/webs/ColorP/functions.js:  
    canvascontext.fillStyle='rgb( '+colourpixel[1]+', '+colourpixel[2]+',   '+colourpixel[3]+')';
called from line 61, column 2 in <anonymous function>(event) in file://localhost/home/angelus/Desarrollo/webs/ColorP/functions.js:
    setColor(x,y);
called from line 55, column 294 in <anonymous function: handle>(a) in file://localhost/home/angelus/Desarrollo/webs/ColorP/jquery.min.js:
    i=i.handler.apply(this,arguments);
called via Function.prototype.apply() from line 49, column 569 in <anonymous function: o>() in file://localhost/home/angelus/Desarrollo/webs/ColorP/jquery.min.js:
    return typeof c!=="undefined"&&!c.event.triggered?c.event.handle.apply(o.elem,arguments):w

いていこうという思いを込めてのオブジェクトのような配列(var colourpixel=new Array(); がある。

"と彼は話します。

役に立ちましたか?

解決

なんなのか最固定していないこ色の状況をすべてが、ここでの問題は、

オペラ指定した場合スタイルとして rgb(...), 例えば:

<div id="colour" style="background-color: rgb(0, 70, 255);">​

ほとんどのブラウザのために $('#colour').css('background-color') しょ: "rgb(0, 70, 255)", が、それだけではありませんの真のオペラだって、六角形の "#0046ff", なおregexんマッチ colourpixel ます null, なの配列。ここを起こすことで生まれる誤差と同じ null[1] するパラメータである。

ここでの試この点を明らかにするため, 試験では他の主要ブラウザ、そしてオペラ座があります。

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top