使用JavaScript或jQuery显示和隐藏帧
我需要隐藏帧“顶框”和“菜单”当我点击任何图像或按钮,并取消隐藏当我再次点击它。有没有一种方法可以让我轻松实现 很抱歉没有发布“topFrame”和“menu”jsp文件,因为这些文件在我的应用程序中是动态呈现的使用JavaScript或jQuery显示和隐藏帧,javascript,jquery,html,Javascript,Jquery,Html,我需要隐藏帧“顶框”和“菜单”当我点击任何图像或按钮,并取消隐藏当我再次点击它。有没有一种方法可以让我轻松实现 很抱歉没有发布“topFrame”和“menu”jsp文件,因为这些文件在我的应用程序中是动态呈现的 <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <script src="/jquery
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<script src="/jquery-1.10.2.min.js" language="javascript"></script>
<style type="text/css"></style>
</head>
<frameset rows="80,*" frameborder="no" border="0" framespacing="0">
<frame src="/someAction1.do" name="topFrame" scrolling="no" noresize="">
<frameset cols="20%,80%*" frameborder="0" framespacing="0" border="0">
<frame src="/someAction2.do" name="menu" marginheight="0" marginwidth="0" noresize="true" scrolling="auto" framespacing="0" border="0" frameborder="0">
<frame src="/someAction2.do" name="information" marginheight="0" marginwidth="0" scrolling="auto" framespacing="0" border="0" frameborder="0">
</frameset>
</frameset>
<noframes>
// ...
</noframes>
</html>
// ...
使用功能显示/隐藏
$('button').on('click',function(){
$('frame[name="topFrame"],frame[name="menu"]').toggle();
});
如果按钮也是动态生成的,那么委托就很重要
$(document).on('click','button_or_img',function(){
$('frame[name="topFrame"],frame[name="menu"]').toggle();
});
我认为它会起作用:
$("#button").click(function(){
$('[name="menu"]').toggle();
$('[name="information"]').toggle();
});
您可以通过fadeToggle()/toggle()进行切换
将此代码添加到页面底部的
正文
结束标记之前:
<script>
(function(){
$('img, button').on("click" , function (e) {
$('frame[name="topFrame"], frame[name="menu"]').toggle();
});
}());
</script>
(功能(){
$('img,button')。打开(“单击”,函数(e){
$('frame[name=“topFrame”],frame[name=“menu”]”)。toggle();
});
}());
我认为以下内容对您有所帮助。代码非常简单,并且是自解释的
<html>
<head>
<script>
function show1()
{
document.getElementById("div_main").style.visibility = "visible";
}
function close_dialog()
{
document.getElementById("div_main").style.visibility = "hidden";
}
</script>
<style>
*
{
margin:0px;
padding:0px;
}
#div_main
{
height:100%;
width:100%;
background-color:rgba(204,204,204,.8);
z-index:300;
position:fixed;
visibility:hidden;
}
#cls_btn
{
height:100px;
width:100px;
margin-left:50%;
}
body
{
background-color:#09F;
}
</style>
</head>
<body>
<div id="div_main">
<input type="button" value="Close Me" onClick="close_dialog()" id="cls_btn">
</div>
<input type="button" value="Click Me" onClick="show1()">
</body>
</html>
函数show1()
{
document.getElementById(“div_main”).style.visibility=“visible”;
}
函数关闭_对话框()
{
document.getElementById(“div_main”).style.visibility=“hidden”;
}
*
{
边际:0px;
填充:0px;
}
#主分区
{
身高:100%;
宽度:100%;
背景色:rgba(204204.8);
z指数:300;
位置:固定;
可见性:隐藏;
}
#cls_btn
{
高度:100px;
宽度:100px;
左边距:50%;
}
身体
{
背景色:#09F;
}
@pc shooter,对不起,我没听清楚。如果您担心的是仍然使用框架集。然后,我会说这是我正在运行的应用程序中的要求。我不能改变密码。谢谢你的回答。这里我有一个问题,我必须在哪个文件中添加此代码,因为您可以看到,在我当前包含HTML文件的框架集中没有body标记。只需在tag/。。。。(function(){$('img,button')。在(“单击”上,function(e){$('frame[name=“topFrame]”,frame[name=“menu”]”)。toggle();};}();我已在文件末尾添加了此脚本,但它不起作用:(我已经开始新的线程,以使我的问题更清楚。请参考此链接。谢谢,在这里我知道了如何选择具有名称属性的框架。很高兴在此提供帮助。祝你好运。
<html>
<head>
<script>
function show1()
{
document.getElementById("div_main").style.visibility = "visible";
}
function close_dialog()
{
document.getElementById("div_main").style.visibility = "hidden";
}
</script>
<style>
*
{
margin:0px;
padding:0px;
}
#div_main
{
height:100%;
width:100%;
background-color:rgba(204,204,204,.8);
z-index:300;
position:fixed;
visibility:hidden;
}
#cls_btn
{
height:100px;
width:100px;
margin-left:50%;
}
body
{
background-color:#09F;
}
</style>
</head>
<body>
<div id="div_main">
<input type="button" value="Close Me" onClick="close_dialog()" id="cls_btn">
</div>
<input type="button" value="Click Me" onClick="show1()">
</body>
</html>