我对 Javascript 很陌生。我一直试图弄清楚这一点,但似乎无法解决。所以我的问题是...
我需要在代码中做什么,以便当您打开“一”并单击“二”时,“一”下面的内容会折叠?
HTML:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Help!</title>
</head>
<body>
<div>
<a href="#" id="1" class="title" name="1">one</a>
</div>
<div id="workdiv1" class="workdiv" style="display:none">content 1
</div>
</div>
<div class="storybottom">
<a href="#" id="2" class="title" name="2">two</a>
</div>
<div id="workdiv2" class="workdiv" style="display:none">content 2
</div>
</div>
<div class="storybottom">
<a href="#" id="3" class="title" name="3">three</a>
</div>
<div id="workdiv3" class="workdiv" style="display:none">content 3
</div>
</div>
<script src="http://code.jquery.com/jquery-1.7.2.min.js"></script>
<script>
$(document).ready(function() {
$('#work').hide();
$('a.title').click(function() {
var id = $(this).attr('id');
$('#workdiv' + id).toggle(150);
return false;
});
});
</script>
</body>
</html>