Hekumok,
алерт всуньте в свою функцию - жмите кнопку и смотрите alert( document.body.style.backgroundColor ); |
<input onclick="color();" value="Жми" type="button">
<script type="text/javascript">
function toHexColor( color ) {
return color.replace( /rgba?\(([^\)]+)\)|#([a-f0-9]{6}|[a-f0-9]{3})/ig, function( m, rgb, hex ) {
if ( rgb = /([0-9\.]+)(\%?)\s*,\s*([0-9\.]+)(\%?)\s*,\s*([0-9\.]+)(\%?)\s*(?:,\s*([0-9\.]+))?/g.exec( rgb || "" ) ) {
hex = parseInt( rgb[2] ? rgb[1] * 2.55 : rgb[1] ).toString( 16 ).replace( /^(.)$/, '0$1' ) +
parseInt( rgb[4] ? rgb[3] * 2.55 : rgb[3] ).toString( 16 ).replace( /^(.)$/, '0$1' ) +
parseInt( rgb[6] ? rgb[5] * 2.55 : rgb[5] ).toString( 16 ).replace( /^(.)$/, '0$1' );
m = rgb[ 7 ] == "" || rgb[ 7 ] === undefined ? 1 : parseFloat( rgb[ 7 ] );
} else if ( hex && ( m = 1 ) ) {
hex = hex.replace( /^(.)(.)(.)$/, "$1$1$2$2$3$3" );
} else {
return m;
}
return "#" + hex;
});
}
function color() {
if ( toHexColor( document.body.style.backgroundColor ) == '')
return document.body.style.backgroundColor='#f00';
if ( toHexColor( document.body.style.backgroundColor ) == '#ff0000')
return document.body.style.backgroundColor='#0f0';
if ( toHexColor( document.body.style.backgroundColor ) == '#00ff00')
return document.body.style.backgroundColor='#f00';
}
</script>
|
devote,
Ну вон жа палитру текущих цветов браузера в его собственном формате - подставлять и сравнивать Свои цвета задаём в палитре - а считываем браузерные |
Deff,
можно но массив огромный получится, если в него впихнуть всю палитру. Хотя если тока нужные значения то да. Норм. |
devote,
Ти мож пихать динамически в один и тот жа span и считывать (*мну по быстрому - попонятней пытался |
Цитата:
|
Цитата:
<input onclick="color();" value="Жми" type="button">
<script type="text/javascript">
var toConvertedColor = (function( b ){
return function( color ) {
b.style.color = color;
return b.style.color;
}
})( document.createElement( 'b' ) );
function color() {
if ( document.body.style.backgroundColor == '')
return document.body.style.backgroundColor='#f00';
if ( document.body.style.backgroundColor == toConvertedColor( '#f00' ) )
return document.body.style.backgroundColor='#0f0';
if ( document.body.style.backgroundColor == toConvertedColor( '#0f0' ) )
return document.body.style.backgroundColor='#f00';
}
</script>
|
Цитата:
|
:blink: Почему -то все одно -синего нет ??? (Опера - ток -красный - и зелёный
|
Цитата:
|
| Часовой пояс GMT +3, время: 04:57. |