我开始用html-css-javascript编程,事情是我有一个main.html,它有一个打开弹出窗口的按钮(popup.html)。
问题出在main.html我有一个复选框,我想从弹出窗口中获取复选框的值。
如果我站在popup.html中,有没有办法获得价值?
从main.html我可以做到
var pecho = document.getElementById("pechoButton");
alert(pecho.checked);
但我想从popup.html
做同样的事情由于
main.html中:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Gim Web</title>
<link href="css.css" rel="stylesheet" type="text/css" />
<script src="./scripts.js"></script>
</head>
<body>
<div id="container">
<div id="encabezado"><img src="Images/banner.jpg" width="940" height="300" alt="banner" /></div>
<div id="cuerpo">
<div id="musculos">
<div id="pecho">
<p>Pecho <input name="pecho" type="checkbox" id="pechoButton"/></p>
</div>
<div id="tricep">
<p>Tricep <input name="Guardar" type="button" onclick="saveData()"/></p>
</div>
</div>
</div>
<div id="pie">Content for id "pie" Goes Here</div>
</div>
</body>
</html>
popup.html:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Datos:</title>
<script src="./scripts.js"></script>
</head>
<body onload="getDatos()">
</body>
</html>
scripts.js中:
// JavaScript Document
function saveData(){
var pecho = document.getElementById("pechoButton");
alert(pecho.checked)
window.open("popUpResult.html", "_blank", "toolbar=yes, scrollbars=yes, resizable=yes, top=500, left=500, width=400, height=400");
}
function fechaHoy(){
var meses = new Array ("Enero","Febrero","Marzo","Abril","Mayo","Junio","Julio","Agosto","Septiembre","Octubre","Noviembre","Diciembre");
var diasSemana = new Array("Domingo","Lunes","Martes","Miércoles","Jueves","Viernes","Sábado");
var fecha=new Date();
var result = diasSemana[fecha.getDay()] + ", " + fecha.getDate() + " de " + meses[fecha.getMonth()] + " de " + fecha.getFullYear();
return(result);
}
function resultados(){
var msj = fechaHoy() + "\n"
/*if (pecho.checked = "true")
{
msj = msj + "Pecho \n"
}*/
return(msj);
}
function getDatos(){
document.write(resultados());
}
答案 0 :(得分:1)
您可以使用sessionStorage并以此方式存储复选框的值:https://developer.mozilla.org/en-US/docs/Web/API/Window/sessionStorage
然后检查弹出窗口中的值。