SoaT
17.01.2011, 22:33
Незамысловатый кодец такой)
Вопрос в следующем: почему при первом клике, после загрузки страницы, div не появляется, а только при втором?
<html>
<head>
<title>test</title>
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8" />
<style type="text/css">
div#text {
border-width: 1px;
border-color: lightgrey;
border-style: dashed;
display: none;
}
a {
color: black;
border-bottom: 1px dashed lightgrey;
outline: none;
text-decoration: none;
}
</style>
<script type="text/javascript">
function opendiv() {
var text=document.getElementById('text');
if (text.style.display=='none')
{
text.style.display='block';
}
else
{
text.style.display='none';
}
}
function closediv() {
var text=document.getElementById('text');
if (text.style.display=='block')
{
text.style.display='none';
}
}
</script>
</head>
<body>
<a href="#" onclick="opendiv()">Скрытый блок:</a>
<div id="text" onclick="closediv()">
<p>Это скрытый блок</p>
<p>Для закрытия кликните по нему</p>
</div>
</body>
</html>
Вопрос в следующем: почему при первом клике, после загрузки страницы, div не появляется, а только при втором?
<html>
<head>
<title>test</title>
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8" />
<style type="text/css">
div#text {
border-width: 1px;
border-color: lightgrey;
border-style: dashed;
display: none;
}
a {
color: black;
border-bottom: 1px dashed lightgrey;
outline: none;
text-decoration: none;
}
</style>
<script type="text/javascript">
function opendiv() {
var text=document.getElementById('text');
if (text.style.display=='none')
{
text.style.display='block';
}
else
{
text.style.display='none';
}
}
function closediv() {
var text=document.getElementById('text');
if (text.style.display=='block')
{
text.style.display='none';
}
}
</script>
</head>
<body>
<a href="#" onclick="opendiv()">Скрытый блок:</a>
<div id="text" onclick="closediv()">
<p>Это скрытый блок</p>
<p>Для закрытия кликните по нему</p>
</div>
</body>
</html>