Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/88.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript HTML表单输出为表_Javascript_Html_Forms - Fatal编程技术网

Javascript HTML表单输出为表

Javascript HTML表单输出为表,javascript,html,forms,Javascript,Html,Forms,我开发了HTML表单,大致如下所示: 之后,我准备了一个外部html文件,该表单输出位于该文件中。我遵循了以下教程: 接下来,因为我只得到冒号后面的纯数据,所以我决定在表中收集它们 在本例中,我修改了javascript代码: <table id="opresults"></table> <script> const resultsList = document.getElementById('opre

我开发了HTML表单,大致如下所示:

之后,我准备了一个外部html文件,该表单输出位于该文件中。我遵循了以下教程:

接下来,因为我只得到冒号后面的纯数据,所以我决定在表中收集它们

在本例中,我修改了javascript代码:

    <table id="opresults"></table>

    <script>
        const resultsList = document.getElementById('opresults')
        const matches = document.querySelectorAll("fieldset");
        new URLSearchParams(window.location.search).forEach((value, name) => {
            resultsList.append(`<th>${name}</th><td>${value}</td>`)
            resultsList.append(document.createElement('br'))
        })
    </script>


我想把它分成两列。这里缺少什么?

一开始就需要正确的HTML表结构

      <table id="opresults" class="outputtable"><p class="outputtablehead">Survey Form - output</p>
    <tr class="colname">
       <th>Form question</th>
        <th colspan="2">Answer</th>
    </tr>

</table>

这里有一个很好的解决方案:


请阅读HTML的介绍性指南,了解
元素
tr
元素以及
br
元素是如何不允许在其中的。并阅读它的作用以及它的参数类型如何影响该行为。请发布相关代码,而不是屏幕截图。这是密码
      <table id="opresults" class="outputtable"><p class="outputtablehead">Survey Form - output</p>
    <tr class="colname">
       <th>Form question</th>
        <th colspan="2">Answer</th>
    </tr>

</table>
     <script>
        const resultsList = document.getElementById('opresults')
        const matches = document.querySelectorAll("fieldset");

        new URLSearchParams(window.location.search).forEach((value, name) => {
            resultsList.append(document.createElement('tbody'))
            resultsList.append(`${name}`)
            resultsList.append(document.createElement('td'))
            resultsList.append(`${value}`)
            resultsList.append(document.createElement('br'))   
        })
    </script>