我想用 javascript 做一些展开/折叠列表。据我所知,我做的一切都是正确的,但是当我点击列表标题时,我得到了
Uncaught SyntaxError: Unexpected token }
在和 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>Kaç Yakıyor?</title>
<style type="text/css">
body
{
background-color:#CCC;
}
h1.header
{
font-family:"Courier New", Courier, monospace;
font-size:45px;
font-style:oblique;
font-weight:400;
text-align:center;
}
div.content
{
margin-top:100px;
margin-left:auto;
margin-right:auto;
width:61%;
background-color:#F00;
}
div.vehicles
{
margin-top:100px;
width:17%;
height:200px;
background-color:#0F6;
float:left;
overflow:auto;
}
li.c
{
font-weight:bold;
}
li
{
font-weight:normal;
display:none;
}
</style>
</head>
<body>
<?php
mysql_connect("localhost","root","123123") or die(mysql_error());
mysql_select_db("kacyakiyor");
$query = "SELECT marka,model from arabalar";
$result = mysql_query($query);
?>
<h1 class="header">KAÇ YAKIYOR</h1>
<hr width="500px"/>
<div class="vehicles">
<h2><strong><em>Araba</em></strong></h2><hr/>
<?php
while($row = mysql_fetch_array($result)){
echo "<ul >";
echo "<li.c id='seen'><a href='#' onclick='show('hidden')'>".$row['marka']."</a>";
echo "<ul>";
echo "<li id='hidden'>".$row['model']."</li>";
echo "</ul>";
echo "</ul>";
}
?>
<h2><strong><em>Motosiklet</em></strong></h2><hr/><br/></div>
<div class="content">asdfasfda</div>
<?php
mysql_close();
?>
<script type="text/javascript">
function show(id){
var hiddenElement = document.getElementById(id);
if(hiddenElement.style.display == 'none')
{
hiddenElement.style.display = 'block';
}
else
{
hiddenElement.style.display = 'none';
}
}
</script>
</body>
</html>
在此之后我立即收到错误,但我没有看到任何额外的“}”。
<div class="content">asdfasfda</div>