2011-09-06 76 views
0

我是一個完整的n00b到CSS和JavaScript,所以對不起,如果這可能是基本的東西..我試圖放在一起顯示建築物概述的表。 當用戶點擊任何樓層鏈接時,一張桌子變成另一張(它們都在不同的div內,當用戶移動鼠標時,它會顯示更多關於每個單元的信息,無論它是否可用於出租,出售,或不可用 我現在試圖創建的是一些鏈接,它們會在單擊時改變每個單元格的背景。例如,當單擊顯示出租單元時,背景在所有單元格上都會更改,其ID = 「租賃」和「都」 審查演示此:http://encanto.ximg.co/overviewdemo.htmlonclick href change td background

繼承人的完整源代碼(包括CSS)第一個表我敢肯定它的一個messup某處我想顯示/隱藏TD細胞太..但我似乎只能找到函數,告訴td改變顏色,當你點擊th e td,而不是href。 正如我所說,我是一個完整的n00b,所以請溫柔。

<style type="text/css"> 
table.overview a { 
border:none;  
display: block; 
} 

table.overview td { 
    max-height:150px; 
    max-width:150px; 
    background:#96843c; 
} 

div.overview td:hover { 
    background:#ffffff; 
} 

div.overview td.white { 
    background:#ffffff; 
} 

div.overview a { 
color: #ffffff; 
text-decoration:none; 
text-align:center; 
letter-spacing: 1px; 
font-size:16px; 
line-height:32px; 
font-family:"Century Gothic", helvetica, sans-serif; 
padding: 2px 5px; 
} 

div.overview p { 
color:#96843c; 
text-decoration:none; 
text-align:center; 
letter-spacing: 1px; 
font-size:10px; 
line-height:10px; 
font-family:Georgia, "Times New Roman", Times, serif; 
} 

div.overview a:hover { 
color: #96843c; 
background: #ffffff; 
font-family: "Century Gothic"; 
} 



</style> 

<script type="text/javascript"><!-- 

function show_visibility(){ 
for(var i = 0,e = arguments.length;i < e;i++){ 
var myDiv = document.getElementById(arguments[i]).style; 
myDiv.display = "block"; 
} 
} 

function hide_visibility(){ 
for(var i = 0,e = arguments.length;i < e;i++){ 
var myDiv = document.getElementById(arguments[i]).style; 
myDiv.display = "none"; 
} 
} 
</script> 

<table summary="" cellpadding="1" cellspacing="1" class="floor"> 

<tr> 

<td> 
<a href="#"onClick="show_visibility('floor1');hide_visibility('floor2');hide_visibility('penthouse') ">Ground Floor</a> 
</td> 

<td> 
<a href="#" onClick="show_visibility('rental');show_visibility('both');hide_visibility('sales');hide_visibility('na') ">Show Rental Units</a> 
</td> 

</tr> 

<tr> 

<td> 
<a href="#" onClick="show_visibility('floor2');hide_visibility('floor1');hide_visibility('penthouse')">1st Floor</a> 
</td> 

</tr> 

<tr> 

<td> 
<a href="#" onClick="show_visibility('penthouse');hide_visibility('floor1');hide_visibility('floor2')">Penthouse</a></td> 
</tr> 
</table> 


<div id='floor1' class="overview" style="display:none"> 

<table summary="" cellpadding="1" cellspacing="1" class="overview" width="630"> 


<tr> 
<td colspan="12" height="25" class="white"></td> 
</tr> 
<tr> 
<td colspan="1" rowspan="7" width="25" class="white"><img src="http://encanto.ximg.co/calle10.jpg" /></td> 
<td colspan="8" height="25" class="white"><img src="http://encanto.ximg.co/adjacent.jpg" /></td> 
<td colspan="1" rowspan="7" width="25" class="white"><img src="http://encanto.ximg.co/calle12.jpg" /></td> 
<td colspan="1" rowspan="7" width="25" class="white"></td> 
</tr> 


<tr> 
<td colspan="4" id="sale"><a href="http://www.encantoriviera.com/unit14/"onfocus="this.blur()"> 
14</a> 
<p> 
<strong>FOR SALE</strong> 
<br /> 
2 Bed/2 Bath 
<br /> 
1131 sq ft./105 sq m. 
</p> 
</a> 
</td> 

<td colspan="4" id="na"><a href="http://www.encantoriviera.com/real-estate/vacation-rentals/"onfocus="this.blur()">1</a> 
<p> 
<strong>NOT AVAILABLE</strong> 
<br /> 
2 Bed/2 Bath 
<br /> 
1677 sq ft./156 sq m. 
</p> 
</a> 

</td> 
</tr> 


<tr> 
<td colspan="2" width="150" id="na"><a href="http://www.encantoriviera.com/"onfocus="this.blur()"> 
13 
<p> 
<strong>NOT AVAILABLE</strong> 
<br /> 
1 Bed/ 1.5 Bath 
<br /> 
840 sq ft./78 sq m. 
</p> 
</a> 

</td> 
<td colspan="4" rowspan="4" width="300" class="white"> 
</td> 

<td colspan="2" width="150" id="na"><a href="http://www.encantoriviera.com/"onfocus="this.blur()"> 
2 
<p> 
<strong>NOT AVAILABLE</strong> 
<br /> 
2 Bed/ 2 Bath 
<br /> 
872 sq ft./82 sq m. 
<br /> 
</p> 
</a> 

</td> 
</tr> 

<tr> 
<td colspan="2" width="150" id="sale"><a href="http://www.encantoriviera.com/unit12/"onfocus="this.blur()"> 
12 
<p> 
<strong>FOR SALE</strong> 
<br /> 
1 Bed/ 1.5 Bath 
<br /> 
850 sq ft./79 sq m. 
<br /> 
</p> 
</a> 

<td colspan="2" width="150" id="na"><a href="http://www.encantoriviera.com/"onfocus="this.blur()"> 
3 
<p> 
<strong>SOLD</strong> 
<br /> 
2 Bed/ 2 Bath 
<br /> 
1130 sq ft./105 sq m. 
</p> 
</a> 

</td> 
</tr> 


<tr> 

<td colspan="2" width="150" id="na"><a href="http://www.encantoriviera.com/"onfocus="this.blur()" > 
11 
<p> 
<strong>NOT AVAILABLE</strong> 
<br /> 
2 Bed/ 2 Bath 
<br /> 
1071 sq ft./101 sq m. 
<br /> 
</p> 
</a> 


<td colspan="2" width="150" id="both"><a href="http://www.encantoriviera.com/unit4/"onfocus="this.blur()"> 
4 
<p> 
<strong>FOR SALE AND RENT</strong> 
<br /> 
2 Bed/ 2 Bath 
<br /> 
1092 sq ft./101 sq m. 
</p> 
</a> 
</td> 
</tr> 

<tr> 

<td colspan="2" width="150" id="na"><a href="http://www.encantoriviera.com/"onfocus="this.blur()" > 
10 
<p> 
<strong>NOT AVAILABLE</strong> 
<br /> 
2 Bed/ 2 Bath 
<br /> 
1087 sq ft./101 sq m. 
</p> 
</a> 

<td colspan="2" width="150" id="na"><a href="http://www.encantoriviera.com/"onfocus="this.blur()"> 
5 
<p> 
<strong>SOLD</strong> 
<br /> 
2 Bed/ 2 Bath 
<br /> 
1092 sq ft./101 sq m. 
</p> 
</a> 
</td> 
</tr> 

<tr> 
<td colspan="2" width="150" id="na"><a href="http://www.encantoriviera.com/"onfocus="this.blur()"> 
9 
<p> 
<strong>SOLD</strong> 
<br /> 
2 Bed/ 2.5 Bath 
<br /> 
1506 sq ft./140 sq m. 
</p> 
</a> 

</td> 

<td colspan="2" width="150" id="na"><a href="http://www.encantoriviera.com/unit8/"onfocus="this.blur()"> 
8 
<p> 
<strong>FOR SALE AND RENT</strong> 
<br /> 
1 Bed/ 1.5 Bath 
<br /> 
915 sq ft./85 sq m. 
</p> 
</a> 
</td> 

<td colspan="2" width="150" id="sale"><a href="http://www.encantoriviera.com/unit7/"onfocus="this.blur()"> 
7 
<p> 
<strong>FOR SALE</strong> 
<br /> 
1 Bed/ 1 Bath 
<br /> 
824 sq ft./75 sq m. 
</p> 
</a> 

</td> 

<td colspan="2" width="150" id="sale"><a href="http://www.encantoriviera.com/unit6/"onfocus="this.blur()"> 
6 
<p> 
<strong>FOR SALE AND RENT</strong> 
<br /> 
1 Bed/ 1.5 Bath 
<br /> 
869 sq ft./81 sq m. 
</p> 
</a> 

</td> 

</tr> 
<tr> 
<td colspan="12" max-height="25" class="white"><img src="http://encanto.ximg.co/avenida20.jpg" /></td> 
</tr> 

</table> 
</div> 

回答

0

你已經擁有了獲得預期結果所需的一切。基本邏輯在你提供的JavaScript函數中都有。您只需告訴JavaScript來更改backgroundColor而不是更改display屬性。

我建議使用更多描述性名稱(例如:highlightCell)製作兩個新函數並更改for循環內部哪些屬性發生更改。