【问题标题】:Show/Hide div during existing script在现有脚本中显示/隐藏 div
【发布时间】:2014-03-08 03:32:47
【问题描述】:

我有一个现有脚本,当按下按钮时,它会在我的网站上执行一项功能。有没有办法让这个按钮同时显示一个 div?当你访问谷歌主页时,你会遇到这个; 然而,当你按谷歌搜索时,你会遇到这个;

我知道这是一个具有不同 url 的不同页面,但是有没有办法通过显示/隐藏 div 来实现这一点?我不介意人们禁用 javascript,因为无论如何我的系统都需要这样做!

【问题讨论】:

  • 为什么不能在现有代码中添加代码以显示/隐藏 div?您现有的代码是什么阻止了您添加额外的功能?

标签: javascript css html web


【解决方案1】:

我找到了答案:jquery: change the URL address without redirecting?

document.location.hash = "show_picture";

Javascript只能控制#之后的东西,google也是这样。使用这一行,您可以重置 #

后面的内容

【讨论】:

    【解决方案2】:

    您可以使用 jquery 来获取您想要的内容,并将以下代码放入按钮单击事件中

    <!DOCTYPE html>
    <html>
    <head>
    <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js">
    </script>
    <script>
    $(document).ready(function(){
      $("#hide").click(function(){
        $("p").hide();
      });
      $("#show").click(function(){
        $("p").show();
      });
    });
    </script>
    </head>
    <body>
    <p>If you click on the "Hide" button, I will disappear.</p>
    <button id="hide">Hide</button>
    <button id="show">Show</button>
    </body>
    </html>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2022-12-10
      • 2022-06-13
      • 1970-01-01
      • 2012-07-03
      • 2016-03-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多