0

contenteditable プロパティをいじっているだけで、backColor コマンドで queryCommandValue を使用しているときに、Internet Explorer 9 は Chrome や Firefox のように RGB や 16 進数ではなく数値を返します。

たとえば、背景色のランダム テキストで queryCommandValue を使用する場合: rgb(255, 204, 0); 52479 を返します。

http://jsfiddle.net/Vu7Dk/12/

IE に RGB カラーを返すように強制するにはどうすればよいですか?

4

1 に答える 1

1

この関数で変換してみてください:

function toColor( input ) {
    if( typeof input != "number" ) {
        return input;
    }

    return "rgb(" + (input & 0xFF) + ", " +
                    ((input & 0xFF00) >> 8) + ", " +
                    ((input & 0xFF0000) >> 16 ) + ")";
}
//Usage
toColor(52479);
//"rgb(255, 204, 0)"

デモhttp://jsfiddle.net/Vu7Dk/16/

于 2012-07-13T08:57:50.287 に答える