87,915
社区成员
发帖
与我相关
我的任务
分享
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
<title>无标题页</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<style type="text/css">
</style>
<script type="text/javascript">
window.onload = function()
{
var tbl = document.getElementById("table1");
var r = 0;
var obj = tbl.getElementsByTagName("a");
for (var i = 0; i < obj.length; i++)
{
obj[i].onclick = function()
{
var o = this.parentNode.parentNode.nextSibling;
if (!window.event)
{
do { o = o.nextSibling; } while (o.nodeType != 1)
}
o.style.display = (o.style.display == "block") ? "none" : "block"
for (var j = 1; j < document.getElementById("table1").rows.length; j =j+ 2)
{
if (document.getElementById("table1").rows[j] !=o)
{
document.getElementById("table1").rows[j].style.display = "none";
}
}
}
}
}
</script>
</head>
<body >
<table id="table1">
<tr>
<td><a href="#">主题一</a></td>
</tr>
<tr style="display:none">
<td>主题一详细内容</td>
</tr>
<tr>
<td><a href="#">主题二</a></td>
</tr>
<tr style="display:none">
<td>主题二详细内容</td>
</tr>
<tr>
<td><a href="#">主题三</a></td>
</tr>
<tr style="display:none">
<td>主题三详细内容</td>
</tr>
</table>
</body>
</html>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
<script type="text/javascript">
var showInfo = function(id) {
var _table = document.getElementById(id);
var _tr = _table.rows;
var _len = _tr.length;
var _self = this;
this.content = [];
for(var i = 0; i< _len; i++) {
if((i % 2) == 0) {
(function(){
var _i = i;
_tr[i].getElementsByTagName('a')[0].onclick = function(){_self.show(_i / 2)};
})();
} else {
this.content.push(_tr[i]);
}
}
}
showInfo.prototype = {
show: function(n) {
var _len = this.content.length;
for(var i = 0; i < _len; i++){
if(i == n) {
this.content[i].style.display = (this.content[i].style.display == 'block') ? 'none' : 'block';
} else {
this.content[i].style.display = 'none';
}
}
}
}
</script>
</head>
<body>
<table id="table1">
<tr>
<td><a href="#">主题一</a></td>
</tr>
<tr id="trSub1" style="display:none">
<td>主题一详细内容</td>
</tr>
<tr>
<td><a href="#">主题二</a></td>
</tr>
<tr id="trSub2" style="display:none">
<td>主题二详细内容</td>
</tr>
<tr>
<td><a href="#">主题三</a></td>
</tr>
<tr id="trSub3" style="display:none">
<td>主题三详细内容</td>
</tr>
</table>
<script type="text/javascript">
new showInfo('table1');
</script>
</body>
</html>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
<title>无标题页</title>
<style type="text/css">
</style>
<script type="text/javascript">
window.onload = function()
{
var tbl = document.getElementById("table1");
var r = 0;
var obj = tbl.getElementsByTagName("a");
for (var i = 0; i < obj.length; i++)
{
obj[i].onclick = function()
{
for (var j = 1; j < document.getElementById("table1").rows.length; j =j+ 2)
{
document.getElementById("table1").rows[j].style.display = "none";
}
var o = this.parentNode.parentNode.nextSibling;
if (!window.event)
{
do { o = o.nextSibling; } while (o.nodeType != 1)
}
o.style.display = (o.style.display == "block") ? "none" : "block"
}
}
}
</script>
</head>
<body >
<table id="table1">
<tr>
<td><a href="#">主题一</a></td>
</tr>
<tr style="display:none">
<td>主题一详细内容</td>
</tr>
<tr>
<td><a href="#">主题二</a></td>
</tr>
<tr style="display:none">
<td>主题二详细内容</td>
</tr>
<tr>
<td><a href="#">主题三</a></td>
</tr>
<tr style="display:none">
<td>主题三详细内容</td>
</tr>
</table>
</body>
</html>
$(".test").click(function(){
$(this).parent().hide();
$(this).parent().next().show();
});
for(var i=1;i<4;i++){
var id = "#trSub" +i;
$(id).click(function(){
$(this).hide();
$(this).prev().show();
});
}
<table id="table1">
<tr>
<td class="test"><a href="#">主题一</a></td>
</tr>
<tr id="trSub1" style="display:none">
<td>主题一详细内容</td>
</tr>
<tr>
<td class="test"><a href="#">主题二</a></td>
</tr>
<tr id="trSub2" style="display:none">
<td>主题二详细内容</td>
</tr>
<tr>
<td class="test"><a href="#">主题三</a></td>
</tr>
<tr id="trSub3" style="display:none">
<td>主题三详细内容</td>
</tr>
</table>
<script>
var curr;
var tbl=document.getElementById("table1");
var a=tbl.getElementsByTagName("a");
for(var i=0;i<a.length;i++){
a[i].onclick=function(){
var obj=this.parentNode.parentNode.nextSibling;
obj.style.display=(obj.style.display=="block")?"none":"block";
if(curr)curr.style.display="none";
curr=obj;
}
}
</script>
<table id="table1">
<tr>
<td><a href="#">主题一</a></td>
</tr>
<tr id="trSub1" style="display:none">
<td>主题一详细内容</td>
</tr>
<tr>
<td><a href="#">主题二</a></td>
</tr>
<tr id="trSub2" style="display:none">
<td>主题二详细内容</td>
</tr>
<tr>
<td><a href="#">主题三</a></td>
</tr>
<tr id="trSub3" style="display:none">
<td>主题三详细内容</td>
</tr>
</table>
<script>
var tbl=document.getElementById("table1");
var a=tbl.getElementsByTagName("a");
for(var i=0;i<a.length;i++){
a[i].onclick=function(){
var obj=this.parentNode.parentNode.nextSibling;
obj.style.display=(obj.style.display=="block")?"none":"block"
}
}
</script>