1

有一个<ul>导航链接。一个特定<li>的实际上变成了 3 个链接。希望那个特定<li>的滑动打开和关闭以显示其他三个链接。

在这里举办

<ul id="courseLinks">
    <li><a href="#"><strong>Week 1</strong> introduction</a></li>
    <li><a href="./homework/week2/week2homework.htm"><strong>Week 2</strong> dev tools + standards</a></li>
    <li><a href="./homework/week3/week3homework.htm"><strong>Week 3</strong> HTML 5 &amp; SEO</a></li>
    <li><a href="#" id="homeworkSlide"><strong>Week 4</strong> css concepts</a></li>
    <li id="slider"><a href="homework/week4/exercise1.htm">Exercise 1</a>
            <a href="homework/week4/exercise2.htm">Exercise 2</a>
            <a href="homework/week4/week4homework.htm">Homework</a></li>
    <li><a href="#"><strong>Week 5</strong> advanced css</a></li>
    <li><a href="#"><strong>Week 6</strong> server side includes</a></li>
    <li><a href="#"><strong>Week 7</strong> site construction</a></li>
    <li><a href="#"><strong>Week 8</strong> development methodology 1</a></li>
    <li><a href="#"><strong>Week 9</strong> user experience</a></li>
    <li><a href="#"><strong>Week 10</strong> social software</a></li>
    <li><a href="#"><strong>Week 11</strong> project work</a></li>
    <li><a href="#"><strong>Week 12</strong> final examination</a></li>
</ul><!--nav-->

查询:

$('#homeworkSlide').click(function() {
  $('#slider').slideToggle('slow', function() {
    // Animation complete.
  });
});

拒绝工作。此时自学javascript,难道就不能这样修改<ul>吗?还是我做错了什么?

4

2 回答 2

1

看了你主机上的源码,发现绑定操作没有绑定在a$(document).ready(...)中,可能是这个原因。

所以,修改代码。

$(document).ready( function() { 
    $('#homeworkSlide').click(function() {
      $('#slider').slideToggle('slow', function() {
        // Animation complete.
      });
    });
} );
于 2012-10-09T03:24:45.673 回答
0

粘贴到控制台时,该代码在该页面上对我来说很好。确保您在准备好的 DOM 上运行它

于 2012-10-09T03:18:46.863 回答