【问题标题】:Javascript hiding map (iframe)Javascript隐藏地图(iframe)
【发布时间】:2017-05-02 15:00:53
【问题描述】:

这是我的代码的 sn-p:

    <div id='content'>
    <div id='map'></div>
    <iframe name="content-wrapper"></iframe>
</div>
<div class="sidebar">
  <div class="container">
    <h2>Bayanihan</h2><br>
    <a href="#" target="content-wrapper">Map</a>   <a onclick= "hide()" href="forum.html" target="content-wrapper">Forum</a>   <a href="insight.html" target="content-wrapper">Insight</a>
    <hr>
    <script>
      function hide() {
        $(map).hide();
      }
    </script>

基本上,我的网站是一个带有侧边栏的地图。在侧边栏中,有三个链接:map, forum, insight。所以我想要发生的是,如果我点击论坛,地图背景将消失并被forum.html 取代,洞察力也是如此。正如您在 sn-p 中看到的那样,我首先在论坛上尝试它。 html 但它不起作用。

【问题讨论】:

  • $(map) - 地图定义是什么?
  • 稍微研究一下 jQuery 选择器。如果您尝试隐藏 ID 为 map 的元素,则需要为其添加前缀 #。此外,由于map 不是变量,因此您需要用引号将其封装起来。应该是$("#map").hide();

标签: javascript jquery html css iframe


【解决方案1】:

我有类似的东西。我所做的是使用这个 js 来更改所有不同站点的内容。
我有一个包含空内容 div 的主页,以及页面内的所有内容都在独立的 html 文件中;当我想更改内容时,我所做的只是使用文件名调用此函数,它会更新所有内容。

function changeContent(url){
  $.ajax({
    crossOrigin: true,
    url: url,
    success: function(data) {
      $('#content').html(data);
    },
    error: function (xhr, status) {
      alert("Something went wrong, try again.");
    },
  });
} 

“a”标签是这样的:
&lt;a class="navbar-brand" href="#index"onclick="changeContent('mainPage.html');"&gt;Stuff&lt;/a&gt; 希望这会有所帮助!

【讨论】:

    猜你喜欢
    • 2016-07-05
    • 1970-01-01
    • 1970-01-01
    • 2021-04-05
    • 1970-01-01
    • 2017-12-02
    • 1970-01-01
    • 1970-01-01
    • 2011-02-13
    相关资源
    最近更新 更多