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

托管here.

<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-->


jQuery:

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


拒绝工作。在这一点上自学javascript,是否无法以这种方式修改<ul>?还是我做错了什么?

最佳答案

我已经阅读了host上的源代码,发现绑定操作未绑定到$(document).ready(...)中,这可能就是原因。

因此,修改代码。

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

关于javascript - 可以.slideToggle()一个特定的<li>吗?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/12792336/

10-09 17:05