當(dāng)前位置:
首頁(yè) >
前端技术
> javascript
>内容正文
javascript
[JavaScript]利用JavaScript控制table中row的显示
生活随笔
收集整理的這篇文章主要介紹了
[JavaScript]利用JavaScript控制table中row的显示
小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
在程序中有時(shí)候我們需要根據(jù)選擇來(lái)顯示我們需要的信息,通過(guò)控制table中row的顯示可以實(shí)現(xiàn)這樣的功能.
?
JavaScript
?<script??language=javascript?>
function?changeRow(id,?status)?{
document.getElementById("Row1").style.display?="none";
document.getElementById("Row2").style.display?="none";
document.getElementById("Row3").style.display?="none";
????var?elm?=?document.getElementById("Row"+id);
????if?(!elm)
????????return?false;
????
????elm.style.display?=?(status?==?true)???""?:?"none";
}
</script>
HTML
<table?width="100%"?border="0">
??<tr>
????<td>
?????????<select?name="select"??onchange="javascript:?changeRow(this.value,true);">
??????????<option?value="0">None</option>
??????????<option?value="1">Row1</option>
??????????<option?value="2">Row2</option>
??????????<option?value="3">Row3</option>
????????</select>
?????????</td>
??</tr>
??<tr?id=Row1?style="display:?none;">
????<td?bgcolor="#99FF00">Row1</td>
??</tr>
??<tr?id=Row2?style="display:?none;">
????<td?bgcolor="#CCCC99">Row2</td>
??</tr>
??<tr?id=Row3?style="display:?none;">
????<td?bgcolor="#FFCC99">Row3</td>
??</tr>
</table>
?
| NoneRow1Row2Row3 |
| Row1 |
| Row2 |
| Row3 |
JavaScript
?<script??language=javascript?>
function?changeRow(id,?status)?{
document.getElementById("Row1").style.display?="none";
document.getElementById("Row2").style.display?="none";
document.getElementById("Row3").style.display?="none";
????var?elm?=?document.getElementById("Row"+id);
????if?(!elm)
????????return?false;
????
????elm.style.display?=?(status?==?true)???""?:?"none";
}
</script>
HTML
<table?width="100%"?border="0">
??<tr>
????<td>
?????????<select?name="select"??onchange="javascript:?changeRow(this.value,true);">
??????????<option?value="0">None</option>
??????????<option?value="1">Row1</option>
??????????<option?value="2">Row2</option>
??????????<option?value="3">Row3</option>
????????</select>
?????????</td>
??</tr>
??<tr?id=Row1?style="display:?none;">
????<td?bgcolor="#99FF00">Row1</td>
??</tr>
??<tr?id=Row2?style="display:?none;">
????<td?bgcolor="#CCCC99">Row2</td>
??</tr>
??<tr?id=Row3?style="display:?none;">
????<td?bgcolor="#FFCC99">Row3</td>
??</tr>
</table>
總結(jié)
以上是生活随笔為你收集整理的[JavaScript]利用JavaScript控制table中row的显示的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: Ten Must-Have Tools
- 下一篇: mac osx 上Eclipse/CDT