【问题标题】:Click button with hide and show单击带有隐藏和显示的按钮
【发布时间】:2023-03-30 03:25:02
【问题描述】:

需要解决这个问题,因为我已经尝试了一个月。您能否查看我的网站以查找不起作用的按钮?

http://www.insightenergy.eu/about-us.php

这有什么问题?

【问题讨论】:

  • edit问题包含屏幕截图和显示您的问题的完整(但简短)代码示例,而不是简单地链接到外部站点,并且还包括指示语言的标签) 你正在使用。
  • 当您在控制台日志中看到时,您的 Javascript 代码存在一些错误...您似乎正在尝试将一些已弃用的属性与新版本的 jQuery 一起使用,这会导致异常.

标签: javascript jquery button


【解决方案1】:

尝试以下代码来展开或最小化容器。

$('.expander').click(function(){

     if(condition){
        $('.expander').next().show();
     }
     else{
        $('.expander').next().hide();
     }});

【讨论】:

    【解决方案2】:

    您需要将一个事件附加到您的按钮,当我调试时,点击时我什么也得不到。

    看看你的网站,我想你可能需要这样的东西: 您的 HTML 结构与此类似:

    HTML

    <ul class="blog-post-full-list">
        <li >
            <div >0</div>
            <div class="expandible">Content</div>
        </li>
        <li >
            <div >1</div>
            <div class="expandible">Content</div>
        </li>
        <li >
            <div >2</div>
            <div class="expandible">Content</div>
        </li>
        <li >
            <div >3</div>
            <div class="expandible">Content</div>
        </li>
    </ul>
    

    所以在你的代码中你可以使用 JQuery 函数切换:

    JS

    $(".blog-post-full-list>li").on('click',function(){
        /*
         *The object this is the li you've clicked on
         *The jQuery function toggle swiches the display ON OFF
         *The number 300 means the duration of the animation. If you don't 
         *    want to animate it just remove the parametter 
         */
        $(this).find(".expandible").toggle(300);
    })
    

    http://jsfiddle.net/vzkUL/2/

    您可以将其添加到 JS 文件中或内联在您的代码中,如下所示:

    <script>
    
    //JQuery onReady
    $(function(){
    
      $(".blog-post-full-list>li").on('click',function(){
        //The object this is the li you've clicked on
        //The jQuery function toggle swiches the display ON OFF
        //The number 300 means the duration of the animation. If you don't want to animate it just remove the parametter
        $(this).find(".expandible").toggle(300);
      })
    
    });
    </script>
    

    【讨论】:

    • 谢谢,它就在附近,但它不会显示和隐藏。由于功能失败
    • 好的,但是您期望什么?如果你不想显示和隐藏,你想从函数中做什么?此外,您应该在问题中添加您想要修复的代码 HTML 以及您尝试实现但它不起作用的 JS 代码。
    • 还是不行。我使用的代码
      • 我们做点什么吧。当我在答案中更新时,尝试将该代码内联添加到脚本标记中
      • 另外,您在此处发布的代码应该添加到您的问题中,在顶部。您可以对其进行编辑并完成信息。事实上,你的否定标点是因为缺乏信息
    猜你喜欢
    • 1970-01-01
    • 2023-01-10
    • 2018-01-22
    • 1970-01-01
    • 2016-05-21
    • 2020-04-24
    • 2020-05-21
    • 2012-05-06
    • 1970-01-01
    相关资源
    最近更新 更多