gpt4 book ai didi

javascript - 引用另一个 .html 文件中的标签

转载 作者:行者123 更新时间:2023-12-03 10:31:26 24 4
gpt4 key购买 nike

我开始使用 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>

脚本.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());
}

最佳答案

您可以使用 sessionStorage 并以这种方式存储复选框的值:https://developer.mozilla.org/en-US/docs/Web/API/Window/sessionStorage

然后检查弹出窗口中的值。

关于javascript - 引用另一个 .html 文件中的标签,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29197797/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com