本文介绍了Jquery切换不工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



 <!DOCTYPE html PUBLIC -  // W3C // DTD XHTML 1.0 Transitional // ENhttp://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional。 dtd> 
< html xmlns =http://www.w3.org/1999/xhtml>
< head>
< meta http-equiv =Content-Typecontent =text / html; charset = utf-8/>
< title>无标题文档< / title>
< style type =text / css>
#one {
border:3px solid#00F;
width:50%;
}
#hideme {
border:3px solid#00F;
width:50%;
display:none;
}
< / style>

< script type =text / javascriptsrc =../_ root / js / jquery / jquery-1.4.2.js>< / script>

< script language =javascripttype =text / javascript>



$(#one)。click(function(){
$(#hideme)。toggle();
});

< / script>

< / head>

< body>

< div id =one>
< a href =#> hello< / a>
< / div>

< div id =hideme>
hi
< / div>


< / body>
< / html>


解决方案

您需要:


  1. 使用

  2. 选择#one div下方的锚点 / ol>

    所以应该是:

      $(document).ready function(){
    $(#one a)。click(function(){
    $(#hideme)。toggle();
    });
    });


    i am trying to get jquery to hide this div and for some reason it is not working what am i doing wrong

    http://stat-me.com/jq.html

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>Untitled Document</title>
    <style type="text/css">
    #one{
        border:3px solid #00F;
        width:50%;
    }
    #hideme{
        border:3px solid #00F;
        width:50%;
        display:none;
    }
    </style>
    
    <script type="text/javascript" src="../_root/js/jquery/jquery-1.4.2.js"></script>
    
    <script language="javascript" type="text/javascript">
    
    
    
    $("#one").click(function () {
    $("#hideme").toggle();
    });
    
    </script>
    
    </head>
    
    <body>
    
    <div id="one">
    <a href="#">hello</a>
    </div>
    
    <div id="hideme">
    hi
    </div>
    
    
    </body>
    </html>
    
    解决方案

    You need to:

    1. Use document.ready
    2. Select the anchor underneath the #one div, not the div itself

    So it should be:

    $(document).ready(function() {
      $("#one a").click(function() {
        $("#hideme").toggle();
      });
    });
    

    这篇关于Jquery切换不工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-15 05:15