Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/451.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/91.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创建另一个表_Javascript_Html_Jquery_Css_Html Table - Fatal编程技术网

如何使用表中的选中值使用javascript创建另一个表

如何使用表中的选中值使用javascript创建另一个表,javascript,html,jquery,css,html-table,Javascript,Html,Jquery,Css,Html Table,我在一个页面中创建了一个带有javascript函数的html表。我需要在表1中每行的最后一列中创建一个复选框,如果选中了复选框,那么表1的元素将添加到表2中,而不选中复选框。我不知道怎么做。有人能帮我吗?请给我举个例子 我使用的代码如下:- 常数a=[“a1”、“a2”、“a3”]; 常数b=[“b1”、“b2”、“b3”]; 常数c=[“c1”、“c2”、“c3”]; 设html=[]; addEventListener(“加载”,函数(){ html.push(“”); 对于(变量i=0

我在一个页面中创建了一个带有javascript函数的html表。我需要在表1中每行的最后一列中创建一个复选框,如果选中了复选框,那么表1的元素将添加到表2中,而不选中复选框。我不知道怎么做。有人能帮我吗?请给我举个例子

我使用的代码如下:-

常数a=[“a1”、“a2”、“a3”];
常数b=[“b1”、“b2”、“b3”];
常数c=[“c1”、“c2”、“c3”];
设html=[];
addEventListener(“加载”,函数(){
html.push(“”);
对于(变量i=0;i

这更接近您想要的

我建议您不要只是把一些猜测的代码放在一起——您发布的代码是一堆事件处理程序、DOM处理和jQuery

常数a=[“a1”、“a2”、“a3”];
常数b=[“b1”、“b2”、“b3”];
常数c=[“c1”、“c2”、“c3”];
设html=[];
设html1=[];
$(函数(){
html.push(“”);
对于(变量i=0;i

常数a=[“a1”、“a2”、“a3”];
常数b=[“b1”、“b2”、“b3”];
常数c=[“c1”、“c2”、“c3”];
设html=[];
设html1=[];
$(函数(){
html.push(“”);
对于(变量i=0;i
表格应在点击复选框时创建?或针对所有复选框?此外,您的代码
名称中有一些打字错误。长度
应为
code1.length
。此处
html.push(“”);
应该是
html1.push..
以及更多请更正并更新您的问题。我给您制作了一个片段。它提供了错误扫描。我向您发送了谷歌驱动器链接,因为有很多文件@mplungjan@Prasad不用了,谢谢你的回答,先生
const a = ["a1", "a2", "a3"];
const b = ["b1", "b2", "b3"];
const c = ["c1", "c2", "c3"];
let html = [];
let html1 = [];
$(function() {
  html.push("<table><tbody>");
  for (var i = 0; i < a.length; i++) {
    j = i + 1;
    html.push(`<tr><td>${j}</td><td>${a[i]}</td><td>${b[i]}</td><td>${c[i]}</td>`);
    html.push(`<td><input type="checkbox" value="${i}" name="code"></td></tr>`)
  }
  html.push("</tbody></table>");
  document.getElementById("container").innerHTML = html.join("");
  var y = 0;
  $("input[type='checkbox']").on("click", function() {
    if (this.checked == true) {
      const i = this.value
        html1.push("<table><tbody>");
        y = y + 1;
        html1.push(`<tr><th>${y}</th><td>${a[i]}</td><td>${b[i]}</td><td>${c[i]}</td></tr>`);
        html1.push("</tbody></table>");
    }

    if (this.checked == false) {
      const i = this.value
        html1.pop("<table><tbody>");
        y = y - 1;
        html1.pop(`<tr><th>${y}</th><td>${a[i]}</td><td>${b[i]}</td><td>${c[i]}</td></tr>`);
        html1.pop("</tbody></table>");
    }
    document.getElementById("result").innerHTML = html1.join("");
  });

});`enter code here`