Javascript 随着div标签代码可见性出现的弹出式开放问题
我有一个Javascript 随着div标签代码可见性出现的弹出式开放问题,javascript,html,jsp,Javascript,Html,Jsp,我有一个pop.jsp,当我点击FindByid时,其中有两个div标记,然后只按id字段显示,如果点击findByname则该字段只显示工作正常的字段。但问题是,当我打开一个pop时,有时字段不可见,有时它工作正常,我不知道为什么会这样?我想在点击相应的按钮时看到相应的字段 注意:有时div标记的可见性仅在internetexplorer上工作,对于其他浏览器,没有可见的div标记,因此请解决我的问题 这是我的index.jsp弹出代码,通过它我可以弹出 <script type="te
pop.jsp
,当我点击FindByid
时,其中有两个div标记,然后只按id字段显示,如果点击findByname
则该字段只显示工作正常的字段。但问题是,当我打开一个pop时,有时字段不可见,有时它工作正常,我不知道为什么会这样?我想在点击相应的按钮时看到相应的字段
注意:有时div标记的可见性仅在internetexplorer
上工作,对于其他浏览器,没有可见的div标记,因此请解决我的问题
这是我的index.jsp弹出代码,通过它我可以弹出
<script type="text/javascript">
function windowLoadByName(windowHeight, windowWidth) {
var centerWidth = (window.screen.width - windowWidth) / 2;
var centerHeight = (window.screen.height - windowHeight) / 2;
newWindow = window.open(
'PopUp.jsp',
'mywindow',
'resizable=0,width=' + windowWidth + ',height=' + windowHeight
+ ',left=' + centerWidth + ',top=' + centerHeight,
"status=1").divHiding(1);
newWindow.focus();
}
function windowLoadById(windowHeight, windowWidth) {
var centerWidth = (window.screen.width - windowWidth) / 2;
var centerHeight = (window.screen.height - windowHeight) / 2;
newWindow = window.open(
'PopUp.jsp',
'mywindow',
'resizable=0,width=' + windowWidth + ',height=' + windowHeight
+ ',left=' + centerWidth + ',top=' + centerHeight)
.divHiding(2);
newWindow.focus();
return newWindow.name;
}
函数windowLoadByName(窗口高度、窗口宽度){
var centerWidth=(window.screen.width-windowWidth)/2;
var centerHeight=(window.screen.height-windowHeight)/2;
newWindow=window.open(
'PopUp.jsp',
“我的窗口”,
'可调整大小=0,宽度='+窗口宽度+',高度='+窗口高度
+'左='+中心宽度+',顶='+中心高度,
“状态=1”)。第(1)款;
newWindow.focus();
}
函数windowLoadById(窗口高度、窗口宽度){
var centerWidth=(window.screen.width-windowWidth)/2;
var centerHeight=(window.screen.height-windowHeight)/2;
newWindow=window.open(
'PopUp.jsp',
“我的窗口”,
'可调整大小=0,宽度='+窗口宽度+',高度='+窗口高度
+'左='+中心宽度+',顶='+中心高度)
.2(2);
newWindow.focus();
返回newWindow.name;
}
这是我的pop.jsp
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<%@ taglib uri="http://jakarta.apache.org/taglibs/input-1.0"
prefix="input"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
<script type="text/javascript">
function loadByName() {
var l = document.getElementById("firstName");
var v = l.value;
window.opener.loadName(v);
window.close();
}
function loadById() {
var ids = document.getElementById("id");
var v = ids.value;
window.opener.loadId(v);
window.close();
}
function divHiding(id) {
var div1 = document.getElementById('div1');
var div2 = document.getElementById('div2');
// Check what the value of the button pressed and displays the correct div
if (id == 1)
div1.style.display = 'block';
else if (id == 2) {
div2.style.display = 'block';
}
}
</script>
</head>
<body>
<form name="employeeForm" method="get">
<div id="div1" style="display: none;">
Employee Name:
<center>
<input type="text" name="firstName" id="firstName" />
</center>
<center>
<input type="submit" name="Search" value="Search"
onclick="loadByName()" />
</center>
</div>
<div id="div2" style="display: none;">
Employee Id:
<center>
<input type="text" name="firstName" id="id" />
</center>
<center>
<input type="submit" name="Search" value="Search"
onclick="loadById()" />
</center>
</div>
</form>
</body>
</html>
在此处插入标题
函数loadByName(){
var l=document.getElementById(“名字”);
var v=l.值;
window.opener.loadName(v);
window.close();
}
函数loadById(){
var id=document.getElementById(“id”);
var v=ids.value;
window.opener.loadId(v);
window.close();
}
函数隐藏(id){
var div1=document.getElementById('div1');
var div2=document.getElementById('div2');
//检查按下按钮的值并显示正确的div
如果(id==1)
div1.style.display='block';
else if(id==2){
div2.style.display='block';
}
}
员工姓名:
员工Id:
问题是因为您正在window.open(..)中调用divHiding函数,并且调用该函数时可能无法加载页面,这就是它有时有效有时无效的原因。
我建议的解决方案是通过url参数传递要显示的div:
newWindow = window.open(
'PopUp.jsp?div=1',
'mywindow',
'resizable=0,width=' + windowWidth + ',height=' + windowHeight
+ ',left=' + centerWidth + ',top=' + centerHeight)
在popup.jsp中,您可以执行以下代码来检查参数是否为1,然后将div1设置为可见,并对div2执行相同的操作
<div id="div1" style="display: <%=(request.getParameter("div").equals("1") ? "block" : "none") %>;">