我有一系列无序列表。每个 li 都有一个特定类别的 id,例如类别 1 或 2。
我有一个 Javascript 方法,它允许用户只显示具有特定 id 的 lis。但是,我希望一些 lis 有多个 id。
例如,有类别和项目。一个项目可以属于多个类别。我如何在我的 HTML 和 JS 中解决这个问题?我试图给一个 li 多于一个 id,但它忽略了 id="3" 并且只考虑了提供的第一个 id,即 id="1"
我希望这是有道理的。这是我的代码:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="description" content="">
<title></title>
<link rel="stylesheet" type="text/css" href="css/style.css">
<!--[if IE]>
<script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script><![endif]-->
<!--[if lte IE 7]> <script src="js/IE8.js" type="text/javascript"></script><![endif]-->
<!--[if lt IE 7]>
<link rel="stylesheet" type="text/css" media="all" href="css/ie6.css"/><![endif]-->
<script type="text/javascript">
function ani(){
document.getElementById('filters').className ='.filters';
}
</script>
<script type="text/javascript">
function toggleVisibility(selectedTab) {
var content = document.getElementsByClassName('content');
for(var i=0; i<content.length; i++) {
if(content[i].id == selectedTab) {
content[i].style.display = 'inline';
} else {
content[i].style.display = 'none';
}
}
}
</script>
<style>
.filters
{
position: relative; margin-top: -10px;
animation-name: slide-down; animation-duration: 1s;
-moz-animation-name: slide-down; -moz-animation-duration: 1s;
-webkit-animation-name: slide-down; -webkit-animation-duration: 1s;
}
@keyframes slide-down
{
from { margin-top: -70px; } to { margin-top: -10px; }
}
@-moz-keyframes slide-down
{
from { margin-top: -70px; } to { margin-top: -10px; }
}
@-webkit-keyframes slide-down
{
from { margin-top: -70px; } to { margin-top: -10px; }
}
</style>
</head>
<body>
<header>
<div class="logo"><img class="logo" src="images/logo2.png"></div>
</header>
<section id="work">
<section id="filters" onclick="ani()">
<a href="#" onclick="toggleVisibility('3');">Web Design and Mobile Applications</a>
<a href="#">Service Design and Digital Branding</a>
<a href="#">Physical Computing</a>
<a href="#">Responsive Environments</a>
<a href="#">Data Visualisation</a>
<a href="#">Interactive Storytelling</a>
</section>
<ul>
<li id="1" id="3" class="content"><a href="#"><img src="images/work/7.jpg"></a></li>
<li id="2" class="content"><a href="#"><img src="images/work/2.jpg"></a></li>
<li id="3" class="content"><a href="#"><img src="images/work/3.jpg"></a></li>
<li id="4" class="content"><a href="#"><img src="images/work/4.jpg"></a></li>
<li id="5" class="content"><a href="#"><img src="images/work/5.jpg"></a></li>
<li id="6" class="content"><a href="#"><img src="images/work/6.jpg"></a></li>
<li id="1" class="content"><a href="#"><img src="images/work/1.jpg"></a></li>
<li id="2" class="content"><a href="#"><img src="images/work/8.jpg"></a></li>
<li id="3" class="content"><a href="#"><img src="images/work/9.jpg"></a></li>
<li id="4" class="content"><a href="#"><img src="images/work/9.jpg"></a></li>
<li id="5" class="content"><a href="#"><img src="images/work/7.jpg"></a></li>
<li id="6" class="content"><a href="#"><img src="images/work/2.jpg"></a></li>
</ul>
</section>
<script type="text/javascript" src="/js/retina/retina.js"></script>
</body>
</html>