【问题标题】:change table cell text to input value with jquery使用jquery将表格单元格文本更改为输入值
【发布时间】:2017-06-09 00:02:21
【问题描述】:

我在从数据库加载的 CRUD 中有一个表,我希望通过将表单元格转换为输入字段来编辑表行,并将单元格文本保留为输入值。我为此使用 jQuery。 到目前为止,我可以在标签内添加输入字段。但是来自所有单元格的数据成为每个输入的值,而不是成为它们各自输入字段的值。这是我的代码

$("#parEdit").click(function(){
$(this).text("Update");
$(this).closest('tr').children().wrapInner('<input type="text" value = ' + $('td').text() + '></input>');
    })

表 身份证|姓名 |职位 |标记|编辑|

1 |艾哈迈德 |第6 | 525 |编辑按钮|

按下编辑按钮后输出是这样的

ID|姓名 |职位 |标记|编辑|

1Ahmad6th525 | 1艾哈迈德6th525 | 1艾哈迈德6th525 | 1艾哈迈德6th525 |更新按钮 |

【问题讨论】:

    标签: jquery html


    【解决方案1】:

    您需要对每个 td 应用换行,您的原始代码插入每个 td 文本。

    $("#parEdit").click(function(){
       $(this).text("Update");
       $(this).closest('tr').children().each(function(){
          $(this).wrapInner('<input type="text" value = ' + $(this).text() + '></input>');
       });
    });
    

    【讨论】:

    • 您缺少点击功能的结束标签。感谢您的帮助
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-10-11
    • 1970-01-01
    • 2014-12-20
    相关资源
    最近更新 更多