我尝试了一个菜单,其中包括通过显示和隐藏来替换div。有点像钻取技术。我觉得它非常啰嗦,因为我是一个菜鸟。任何人都可以提供更清洁或更美观的技术。我错过了这一点吗?
由于
请参阅fiddle
HTML
<div class="first">Choose a Department</div>
<div class="second">
<table class="Menu">
<tr>
<td>
<div class="third">Technology</div>
</td>
<td>
<div class="forth">Vehicles</div>
</td>
</tr>
</table>
</div>
<div class="seventh">
<table class="Menu">
<tr>
<td>
<div class="all"><a>Headphones</a>
</div>
</td>
<td>
<div class="all"><a>Watches</a>
</div>
</td>
<td>
<div class="nineth">Back</div>
</td>
</tr>
</table>
</div>
<div class="sixth">
<table class="Menu">
<tr>
<td><a>Engine-Powered</a>
</td>
<td><a>Human-Powered</a>
</td>
<td>
<div class="fifth">Back</div>
</td>
<td>
<div class="eighth">Top</div>
</td>
</tr>
</table>
</div>
JS
$(document).ready(function () {
$('.first').show();
$('.second, .all, .seventh, .sixth').hide();
$('.first').click(function () {
$('.first, .second').hide();
$('.second').show();
return false;
});
});
$('.third').click(function () {
$('.second').hide();
$('.all, .seventh').show();
return false;
});
$('.forth').click(function () {
$('.second').hide();
$('.sixth,.eighth').show();
return false;
});
$('.fifth').click(function () {
$('.fifth, .sixth').hide();
$('.second').show();
return false;
});
$('.nineth').click(function () {
$('.seventh, .nineth').hide();
$('.second').show();
return false;
});
$('.eighth').click(function () {
$('.sixth, .fifth').hide();
$('.second').show();
return false;
});
CSS
table {
text-align:center;
width:80%;
cursor:pointer;
}
tr {
width:50%;
background:red;
}
答案 0 :(得分:2)
首先,这类问题更适合https://codereview.stackexchange.com/
那说了一些建议:
<table>
进行布局,除非您实际渲染属于表格的数据/内容。