javascript - 如何使用 JavaScript 在新窗口中从主页打开功能?
问题描述
我试图弄清楚如何让我的 HTML 按钮在按下时打开 JavaScript 函数,在新选项卡中打开这些函数,这样我就可以返回并单击新选项卡。这是大学作业,教授不想超过一页,必须打开功能(加法和乘法表分开)。
我一直在尝试从使变量成为全局变量到将变量嵌套到 main() 变量中的所有方法,但没有任何效果。它指出未定义加法和乘法函数。
我对 JavaScript 很陌生,因为这是我的第一个学期,如果这是非常基础的,我深表歉意。
<!DOCTYPE html>
<head>
<title>Math Tables</title>
<script type="text/javascript">
function multiplicationTable(table){
document.write("<table border='1' width='300' cellspacing='0' cellpadding='3'>");
document.write("<tr>");
document.write("<td> * </td>");
for (x = 1; x <=10; x++){
document.write("<td>"+ x +"</td>");
}
for (y = 1; y <= 10; y++) {
document.write( "<tr>");
document.write( "<td>" + y + "</td>");
for (z = 1; z <= 10; z++) {
document.write("<td>" + (y * z) + "</td>");
}
document.write( "</tr>");
}
document.write( "</table>");
}
function additionTable(){
document.write("<table border='1' width='300' cellspacing='0' cellpadding='3'>");
document.write("<tr>");
document.write("<td> * </td>");
for (x = 1; x <=10; x++){
document.write("<td>"+ x +"</td>");
}
for (y = 1; y <= 10; y++) {
document.write( "<tr>");
document.write( "<td>" + y + "</td>");
for (z = 1; z <= 10; z++) {
document.write("<td>" + (y + z) + "</td>");
}
}
}
</script>
</head>
<body>
<h1>Math Tables</h1>
<p>
<input type="button" value="Addition Table" id="addition" onclick="additionTable();"/><br />
<input type="button" value="Multiplication Table" id="multiplication"onclick="multiplicationTable();" /></p>
</body>
</html>
解决方案
推荐阅读
- sockets - 大多数防火墙默认打开哪些端口/推送通知如何工作?
- javascript - 尝试传递数组参数以创建动态 URL
- ssl - 带有gradle的intellij中的SSL证书问题
- react-native - 我可以从 react-native-device-info 获得一些示例输出吗?
- visual-studio-code - 使用 Visual Studio Code 设置 Flutter
- scons - scons 别名导致 python 异常
- javascript - Javascript 堆栈具有相同名称的项目并仅获得最高和最低价格
- python - 无法根据规则“安全”将数组数据从 dtype('float64') 转换为 dtype('int32')
- php - htmlspecialchars 未按预期工作
- android - Android - 1个按钮的多个手指触摸