使用innerHTML将单元格数据写入HTML表格
我无法将下面的最终函数 displayLetter(a, b, c, d, e,f, g) 组合在一起,并使用variableTest() 中的数组元素和变量写入innerHTML 中的表。我知道我需要使用 .length 并确定我需要多少个单元格。 W3C 只让我到目前为止。感谢您的帮助!
<html>
<head>
<title>
</title>
<script>
</script>
</head>
<body>
<h1>TEST THIS SCRIPT</h1>
<table border="1">
<tr>
<th>A</th>
<th>B</th>
<th>C</th>
<th>D</th>
<th>E</th>
<th>F</th>
<th>G</th>
</tr>
<a href="add data" id="reload">Add Employee</a>
</body>
<html>
我的JS:
function addData()
{
var testarray = new Array();
testarray[0] = window.prompt("Enter a letter", "z");
variableTest(x, y);
displaySalary(a, b, c, d, e, f, g);
}
function variableTest(x, y)
{
a=1;
b=2;
c=3;
d=4;
e=5;
}
displayLetter(a, b, c, d, e, f, g)
{
// Code to write the variables to the table
}
I'm having trouble putting together the final function displayLetter(a, b, c, d, e,f, g) below and writing to a table in innerHTML with the array element and variables in variableTest(). I know I need to use .length and to determine how many cells I need. W3C only gets me so far. Thanks for the help!
<html>
<head>
<title>
</title>
<script>
</script>
</head>
<body>
<h1>TEST THIS SCRIPT</h1>
<table border="1">
<tr>
<th>A</th>
<th>B</th>
<th>C</th>
<th>D</th>
<th>E</th>
<th>F</th>
<th>G</th>
</tr>
<a href="add data" id="reload">Add Employee</a>
</body>
<html>
MY JS:
function addData()
{
var testarray = new Array();
testarray[0] = window.prompt("Enter a letter", "z");
variableTest(x, y);
displaySalary(a, b, c, d, e, f, g);
}
function variableTest(x, y)
{
a=1;
b=2;
c=3;
d=4;
e=5;
}
displayLetter(a, b, c, d, e, f, g)
{
// Code to write the variables to the table
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我不太确定你想做什么,但很少有什么事情会出现。我建议您在任何函数之外声明
var testarray = new Array();
。然后在函数addData()
{
testarray.push(window.prompt("输入一个字母"));
}
variableTest() 应该做什么?
调用 addDate 时是否应该将提示文本添加到该表的单元格中?
I'm not quite sure what you are trying to do but few things pop out. I'd suggest you declare
var testarray = new Array();
outside of any function. Then infunction addData()
{
testarray.push (window.prompt("Enter a letter"));
}
What is variableTest() supposed to do?
When calling addDate is it supposed to add the prompted text into a cell in that table?