WCM - Das österreichische Computer Magazin Forenübersicht
 

Zurück   WCM Forum > Rat & Tat > Programmierung

Programmierung Rat & Tat für Programmierer

Microsoft KARRIERECAMPUS

Antwort
 
Themen-Optionen Ansicht
Alt 25.01.2012, 20:23   #1
Undertaker
Veteran
 
Benutzerbild von Undertaker
 
Registriert seit: 15.07.2009
Ort: Ybbs
Beiträge: 207


Frage 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.
____________________________________
A HTLer der nix trinkt, is wie a Sinus der ned schwingt.
Undertaker ist offline   Mit Zitat antworten
Alt 26.01.2012, 15:03   #2
athropos
Hero
 
Registriert seit: 24.07.2001
Alter: 46
Beiträge: 801


athropos eine Nachricht über Skype™ schicken
Standard

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
____________________________________
Einstein, Pascal and Newton are playing hide and seek. Einstein is \"it\" so he faces the wall, closes his eyes and counts to π.
Pascal runs off like an idiot but Newton pulls out a piece of chalk and draws a 1m x 1m square on the ground and then stands in it\'s centre.

Einstein\'s done counting and turns around and sees Newton, so he grabs him and screams \"I found Newton!\"

Then Newton smirks and says, \"I\'m not Newton, I\'m Pascal\".
athropos ist offline   Mit Zitat antworten
Alt 27.01.2012, 23:00   #3
Undertaker
Veteran
 
Benutzerbild von Undertaker
 
Registriert seit: 15.07.2009
Ort: Ybbs
Beiträge: 207


Standard

Zitat:
Zitat von athropos Beitrag anzeigen
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.
____________________________________
A HTLer der nix trinkt, is wie a Sinus der ned schwingt.
Undertaker ist offline   Mit Zitat antworten
Alt 01.02.2012, 12:26   #4
athropos
Hero
 
Registriert seit: 24.07.2001
Alter: 46
Beiträge: 801


athropos eine Nachricht über Skype™ schicken
Standard

Fehlerkonsole im FF: STRG+SHIFT+J
____________________________________
Einstein, Pascal and Newton are playing hide and seek. Einstein is \"it\" so he faces the wall, closes his eyes and counts to π.
Pascal runs off like an idiot but Newton pulls out a piece of chalk and draws a 1m x 1m square on the ground and then stands in it\'s centre.

Einstein\'s done counting and turns around and sees Newton, so he grabs him and screams \"I found Newton!\"

Then Newton smirks and says, \"I\'m not Newton, I\'m Pascal\".
athropos ist offline   Mit Zitat antworten
Alt 04.02.2012, 14:47   #5
Undertaker
Veteran
 
Benutzerbild von Undertaker
 
Registriert seit: 15.07.2009
Ort: Ybbs
Beiträge: 207


Standard

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
____________________________________
A HTLer der nix trinkt, is wie a Sinus der ned schwingt.
Undertaker ist offline   Mit Zitat antworten
Antwort


Aktive Benutzer in diesem Thema: 1 (Registrierte Benutzer: 0, Gäste: 1)
 

Forumregeln
Es ist Ihnen nicht erlaubt, neue Themen zu verfassen.
Es ist Ihnen nicht erlaubt, auf Beiträge zu antworten.
Es ist Ihnen nicht erlaubt, Anhänge hochzuladen.
Es ist Ihnen nicht erlaubt, Ihre Beiträge zu bearbeiten.

BB-Code ist an.
Smileys sind an.
[IMG] Code ist an.
HTML-Code ist aus.

Gehe zu


Alle Zeitangaben in WEZ +2. Es ist jetzt 20:01 Uhr.


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