这是我的代码片段:
<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 。在侧边栏中,有三个链接: map 、论坛、见解
。所以我想要发生的是,如果我单击论坛, map 背景将消失并被 forum.html
取代,洞察力也是如此。正如您在代码片段中看到的那样,我首先在论坛上进行了尝试。 html 但它不起作用。
最佳答案
我有类似的东西。我所做的是使用此 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”标签是这样的:
<a class="navbar-brand" href="#index"onclick="changeContent('mainPage.html');">Stuff</a>
希望这对您有所帮助!
关于Javascript隐藏 map (iframe),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41190754/