简体   繁体   English

.hide不起作用

[英].hide doesn't work

I am making a jeopardy game. 我正在制作危险游戏。 When I click a div I want to do some effect on it. 当我单击一个div时,我想对其进行一些处理。 However, I can't even get a simple .hide to work. 但是,我什至无法获得简单的.hide来工作。 Any ideas? 有任何想法吗?

<!DOCTYPE html>
<html lang="en">
    <head>
        <title>Jeopardy</title>
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <link href="css/bootstrap-responsive.css" rel="stylesheet">
        <link href="css/bootstrap.css" rel="stylesheet">        
        <link href="css/customStyles.css" rel="stylesheet">     
        <script src="http://code.jquery.com/jquery-latest.js"></script>
        <script src="js/flip.js"></script>
    </head>
    <body>
        <div class ="container"> 
            <div class="row">   
                <div class="prizeAmount">                               
                    <div class="span2">     
                        <h3 id="test">100</h3>                          
                    </div>
                    <div class="span2">     
                        <h3>100</h3>                                
                    </div>  
                    <div class="span2">     
                        <h3>100</h3>                                
                    </div>
                        <div class="span2">     
                            <h3>100</h3>                            
                    </div>
                    <div class="span2">     
                        <h3>100</h3>                        
                    </div>  
                    <div class="span2">     
                        <h3>100</h3>    
                    </div>  
                </div>
            </div>
        </div><!--close container-->
    </body>
</html> 

javascript javascript

$(function() {    
    $('#span2').click(function() {
        $(this).hide(400);
        /*$('#span2').hide(400);  <--tried this also */
    });
});

I've used jquery to animate navigation on a site before. 我以前使用过jquery来动画化网站上的导航。 Am i missing something obvious? 我缺少明显的东西吗?

Your 你的

$('#span2') // id selector

Should be 应该

$('.span2') // class selector

Since it's a class 因为这是一堂课

Your problem is that you are using the hash # which is the id selector instead of the class selector which is a dot . 您的问题是您使用的是哈希号# ,它是ID选择器,而不是选择器,它是 . .

Try 尝试

$(function() {    
    $('.span2').click(function() {
        $(this).hide(400);
     });
 });

You might want to read up more on the different jQuery Selectors on the official documentation 您可能需要阅读官方文档中有关jQuery选择器的更多信息

You dont have any elements with ID "span2", they are all CLASS=span2. 您没有任何ID为“ span2”的元素,它们都是CLASS = span2。

Try this: 尝试这个:

$(function() {    
 $('.span2').click(function() {
  $(this).hide(400);
 });
});

Note: this will effect ALL elements with the class "span2" if you don't want that behavior, then use ID="span2" for a single element, and use unique names for each. 注意:如果您不希望使用“ span2”类,则将影响所有具有“ span2”类的元素,然后对单个元素使用ID =“ span2”,并对每个元素使用唯一的名称。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM