简体   繁体   English

在列(脚本)中添加文本框

[英]adding text-box in column (script)

I have this code (in script): 我有以下代码(在脚本中):

var response = [{
      "A":"a2",
      "B":"b2",
      "C":"c2"
     },
     {
      "A":"a3",
      "B":"b3",
      "C":"c3"
    },
    {
      "A":"a4",
      "B":"b4",
      "C":"c4"
    }];

    $.each(response, function(i, item) {
                $('<tr>').html(
                //"<tr>" +
                "<td>" + response[i].A + "</td><td>" + response[i].B + "</td><td>" + response[i].C + "</td>" + "</tr>").appendTo('#MyTable tbody');
        });

and I want to change one of column (just for exp it's will be "A") to be "edited" by text-box. 并且我想更改一列(仅用于exp,它将是“ A”)由文本框“编辑”。 I am tring this: 我正在努力:

...                `"<td><input type="text">" + response[i].A + "</td><td>" + response[i].B + "</td><td>" + response[i].C + "</td>" + "</tr>").appendTo('#MyTable tbody');`...

but it's not working. 但它不起作用。 any help please! 任何帮助,请!

Try saying This 尝试说这个

var firstcell = "<td><input type="text" value="VALUE"</td>";
firstcell = firstcell.replace('VALUE', response[i].A);

Use this for first cell in each Row. 将其用于每个行的第一个单元格。 After that append this in whole row. 之后,将其整行追加。

If i understood correctly, 如果我理解正确,

Instead of creating <tr> , later adding contents to it using html() and finally appending to do the <table> , you can directly add everything altogether to the <table> using append() method. 无需创建<tr> ,而是稍后使用html()向其中添加内容并最终添加以执行<table> ,您可以使用append()方法将所有内容直接添加到<table>

 $.each(response, function(i, item) {
     $('#MyTable tbody').append("<tr>"
          +"<td><input type='text' value='"+ response[i].A +"'/> </td><td><input type='text' value='"+ response[i].B +"'/></td><td><input type='text' value='"+ response[i].C +"'/></td>"
          + "</tr>");
     });

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM