WCM Forum

WCM Forum (http://www.wcm.at/forum/index.php)
-   Programmierung (http://www.wcm.at/forum/forumdisplay.php?f=17)
-   -   Javascript Hintergrundfarbe herauslesen und mehr. (http://www.wcm.at/forum/showthread.php?t=243817)

Undertaker 25.01.2012 20:23

Javascript Hintergrundfarbe herauslesen und mehr.
 
Hallo.

Ich stehe momentan vor einem Problem. Ich arbeite gerade an einem Farbwähler. HEX-Werte eingeben und mit diesen den Hintergrund ändern klappt perfekt. Jedoch muss ich einige Buttons hinzufügen die: 8 bzw 1 Farbwärte zu Rot/Grün/Blau hinzufügen bzw abziehen.

Mir wurde sofort klar, dass ich irgendwie die Hintergrundfarbe auslesen muss. Habe gegoogelt und bin auch fündig geworden.

Zitat:

var farbe = document.body.style.backgroundColor;

str_bg_colour=farbe + (document.Farbwahl.Bred.value+8) + document.Farbwahl.Bgreen.value + document.Farbwahl.Bblue.value;
Das Problem ist aber, dass die Farbe nur 1 MAL geändert wird und bei erneutem Drücken nichts passiert.
Hier mal mein Dokument:

Zitat:

<html>
<head>
<title>Farbwähler HEX 2 -> RGB</title>
<script type="text/javascript" language="JavaScript">
function repaint_bg()
{
var str_bg_colour="abc";
str_bg_colour=document.Farbwahl.Bred.value + document.Farbwahl.Bgreen.value + document.Farbwahl.Bblue.value;
document.bgColor=str_bg_colour;
}
function repaint_bg_PPR()
{
var str_bg_colour="abc";
var farbe = document.body.style.backgroundColor;
str_bg_colour=farbe + (document.Farbwahl.Bred.value+8) + document.Farbwahl.Bgreen.value + document.Farbwahl.Bblue.value;
document.bgColor=str_bg_colour;
}
function repaint_bg_PPG()
{
var str_bg_colour="abc";
str_bg_colour=document.Farbwahl.Bred.value + (document.Farbwahl.Bgreen.value+8) + document.Farbwahl.Bblue.value;
document.bgColor=str_bg_colour;
}
function repaint_bg_PPB()
{
var str_bg_colour="abc";
str_bg_colour=document.Farbwahl.Bred.value + document.Farbwahl.Bgreen.value + (document.Farbwahl.Bblue.value+8);
document.bgColor=str_bg_colour;
}
function repaint_bg_PR()
{
var str_bg_colour="abc";
str_bg_colour=(document.Farbwahl.Bred.value+1) + document.Farbwahl.Bgreen.value + document.Farbwahl.Bblue.value;
document.bgColor=str_bg_colour;
}
function repaint_bg_PG()
{
var str_bg_colour="abc";
str_bg_colour=document.Farbwahl.Bred.value + (document.Farbwahl.Bgreen.value+1) + document.Farbwahl.Bblue.value;
document.bgColor=str_bg_colour;
}
function repaint_bg_PB()
{
var str_bg_colour="abc";
str_bg_colour=document.Farbwahl.Bred.value + document.Farbwahl.Bgreen.value + (document.Farbwahl.Bblue.value+1);
document.bgColor=str_bg_colour;
}
</script>
</head>
<body>
<form method="get" name="Farbwahl">
<table border="1">
<tr>
<td>R</td>
<td>G</td>
<td>B</td>
</tr>
<tr>
<td>
<input type="button" value="++" onClick="repaint_bg_PPR()" /><br />
<input type="button" value="+" onClick="repaint_bg_PR()" /><br />
<input type="text" name="Bred" size="2" maxlength="2" /><br />
</td>
<td>
<input type="button" value="++" onClick="repaint_bg_PPG()" /><br />
<input type="button" value="+" onClick="repaint_bg_PG()" /><br />
<input type="text" name="Bgreen" size="2" maxlength="2" /><br />
</td>
<td>
<input type="button" value="++" onClick="repaint_bg_PPB()" /><br />
<input type="button" value="+" onClick="repaint_bg_PB()" /><br />
<input type="text" name="Bblue" size="2" maxlength="2" /><br />
</td>
</tr>
</table>
<input type="button" value="&Auml;ndern" onClick="repaint_bg()" />
<input type='button' value='Zur&uuml;ck' onClick='history.back()' />
</form>
</body>
</html>
Hat jemand einen Vorschlag?

Danke im Voraus.

athropos 26.01.2012 15:03

schon mal in die Fehlerkonsole geschaut, ob nicht irgendwo ein typo drinhängt?
weiters ist gerade der IE mitunter sehr intolerant, was unsauberes html angeht, dh jag sicherheitshalber den code mal durch den w3c validator

Undertaker 27.01.2012 23:00

Zitat:

Zitat von athropos (Beitrag 2468103)
schon mal in die Fehlerkonsole geschaut, ob nicht irgendwo ein typo drinhängt?
weiters ist gerade der IE mitunter sehr intolerant, was unsauberes html angeht, dh jag sicherheitshalber den code mal durch den w3c validator

Hm das kommt jetzt sicher blöd.. Fehlerkonsole? (Ich schreibe nur in Notepad++...)

Benutze eh FF.

werde dies testen, jedoch erst am Ende des WE weil ich momentan nicht zu hause bin und hier gerade mit dem Handy online bin. (und es zankt bis zum geht nicht mehr..)

Danke jedoch für deine Antwort.

athropos 01.02.2012 12:26

Fehlerkonsole im FF: STRG+SHIFT+J

Undertaker 04.02.2012 14:47

Danke für den Tipp!

Übrigens, das Problem hat sich jt. gelöst. Ein Freund hat mir geholfen. Dennoch danke für den Tipp mit der Fehlerkonsole ;)


Alle Zeitangaben in WEZ +2. Es ist jetzt 15:52 Uhr.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
© 2009 FSL Verlag