0

我试图在页面加载时简单地隐藏一些东西......我实际上最终会隐藏很多东西,但现在我可以隐藏它。我滚动了一些我在 SO 上找到的答案,但无法正常工作。我必须为 css 保留 .jumbotron 类,所以我只是在它上面添加了一个 id ............不确定这是问题还是什么......这是我的代码。我省略了开头,因为没有人真正需要看到这一点。

  <!-- Jumbotron -->
      <div class="jumbotron">
        <h1>Data Loader</h1>
        <p class="lead">Follow the directions to load your data.</p>
        <a class="btn btn-large btn-success" href="#">Start</a>
      </div>

      <div id="second_slide" class="jumbotron" >
        <h1>Data Loader</h1>
        <p class="lead">Follow the directions to load your data.</p>
        <a class="btn btn-large btn-success" href="#">Start</a>
      </div>

      <hr>

      <!-- Example row of columns -->
      <div class="row-fluid">
        <div class="span4">

        </div>
      </div>

      <hr>

      <div class="footer">
        <p>&copy; Company 2013</p>
      </div>

    </div> <!-- /container -->
    <script>
      //doesn't work
     $(document).ready(function(){

    $('.jumbotron #second_slide').click(function(){
      var index=$('.jumbotron #second_slide').index(this);
      $('.jumbotron #second_slide').hide();
    });

});
4

6 回答 6

1

It doesn't work because there is no element with an ID of 'second_slide' inside an element with a class of 'jumbotron'.

Try this:

$('.jumbotron#second_slide').hide();
于 2013-08-13T12:52:56.680 回答
0

It looks like the problem is the selector in $('.jumbotron #second_slide'). All you need is the id: $('#second_slide').

$('.jumbotron #second_slide') is trying to find an element with id="second_slide" within the class="jumbotron" divs.

于 2013-08-13T12:53:06.553 回答
0

Did you read http://api.jquery.com/category/selectors/ ? Writing something like .clazz #id you actually want to search for the id inside .clazz. You should probably iterate through those jumbotrons and select one you're interested in, then extract that component.

于 2013-08-13T12:53:13.707 回答
0

我试试看:

$(function(){
    $('#second_slide').click(function(){
        $(this).hide();
    });
});

这就是整个<script>元素。

于 2013-08-14T06:18:52.327 回答
0

尝试这个

   <div class="jumbotron">
    <h1>Data Loader</h1>
    <p class="lead">Follow the directions to load your data.</p>
    <a class="btn btn-large btn-success" href="#">Start</a>


  <div id="second_slide" class="jumbotron" >
    <h1>Data Loader</h1>
    <p class="lead">Follow the directions to load your data.</p>
    <a class="btn btn-large btn-success" href="#">Start</a>
  </div></div>
于 2013-08-13T12:50:54.650 回答
0

尝试

 $('#second_slide').click(function(){
      var index=$('#second_slide').index(this);
      $(this).hide();
    });
于 2013-08-13T12:51:37.433 回答