使用innerHTML将单元格数据写入HTML表格

发布于 2024-08-18 17:35:08 字数 1131 浏览 2 评论 0原文

我无法将下面的最终函数 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

晒暮凉 2024-08-25 17:35:08

我不太确定你想做什么,但很少有什么事情会出现。我建议您在任何函数之外声明 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 in
function 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?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文