Javascript隐藏映射(iframe)
这是我的代码片段:Javascript隐藏映射(iframe),javascript,jquery,html,css,iframe,Javascript,Jquery,Html,Css,Iframe,这是我的代码片段: <div id='content'> <div id='map'></div> <iframe name="content-wrapper"></iframe> </div> <div class="sidebar"> <div class="container"> <h2>Bayanihan</h2><br>
<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>
巴亚尼汉
函数hide(){
$(map.hide();
}
基本上,我的网站是一个带有边栏的地图。在侧边栏中,有三个链接:
map、forum、insight
。因此,我希望发生的是,如果我单击Forum,地图背景将消失,并将替换为Forum.html
,insight也是如此。正如您在片段中看到的,我首先在论坛上尝试它。但是它不工作 我也有类似的经历。我所做的是使用这个js来更改所有不同站点的内容。我有一个主页,里面有一个空的content 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”标签是这样的:
希望这有帮助
$(map)
-map的定义是什么?研究一下jQuery选择器。如果试图隐藏ID为map
的元素,则需要在其前面加上#
。此外,由于map
不是一个变量,因此需要用引号将其封装起来。它应该是$(“#map”).hide()代码>