webForumDet fria alternativet

bakgrundsfärg i tabell

2 svar · 307 visningar · startad av best_b

best_bMedlem sedan apr. 200425 inlägg
#1

Hej

Skulle behöva hjälp med att byta bakgrundsfärg i en enskild cell i
en tabell:

<html>
<head>
<script language="JavaScript">
function blue(){
document.body.bgColor = "blue"
}
</script>

<script language="JavaScript">
function white(){
document.body.bgColor = "white"
}
</script>

</head>
<body bgcolor="gray">
<table width="50%">
<tr>
<td width="50%">
<form>
<input type="button" value="Hej" OnClick="blue()">
</td>
<td width="50%">
<input type="button" value="Då" Onclick="white()">
</td>
</tr>
</table>
</body>
</html>

Alltså det jag vill göra är att när nån clickar på någon av knapparna vill jag göra så den cellen ändrar bakgrundsfärg.

Peter SMedlem sedan dec. 20025 483 inlägg
#2
 1: <html>
 2: <head>
 3: <script language="JavaScript">
 4: function blue(obj){
 5:     while ((obj = obj.parentNode).nodeName != "TD");
 6:     obj.style.backgroundColor = "blue";
 7: }
 8: </script>
 9: 
10: <script language="JavaScript">
11: function white(obj){
12:     while ((obj = obj.parentNode).nodeName != "TD");
13:     obj.style.backgroundColor = "white";
14: }
15: </script>
16: 
17: </head>
18: <body bgcolor="gray">
19: <table width="50%">
20: <tr>
21: <td width="50%">
22: <form>
23: <input type="button" value="Hej" OnClick="blue(this)">
24: </td>
25: <td width="50%">
26: <div><input type="button" value="Då" Onclick="white(this)"></div>
27: </td>
28: </tr>
29: </table>
30: </body>
31: </html>

:)

best_bMedlem sedan apr. 200425 inlägg
#3

it works

132 ms totalt · 3 externa anrop · v20260731065814-full.beb2e261
0 ms — hämta forumlista (cache)
0 ms — hämta statistik (cache)
130 ms — hämta tråd, inlägg och bilagor (db)