jQuery - 内联编辑表格行 [英] jQuery - Edit a table row inline

查看:18
本文介绍了jQuery - 内联编辑表格行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个包含任意列和行的表格.虽然这个事实无关紧要,但我想要做的就是开发一个函数,将一行(或多行)转换为一系列包含表中数据的文本输入(如果单元格中没有数据,则为空).

我找不到任何人明确这样做的例子,所以我想知道这里的人认为什么是找到解决方案的最佳方式.

解决方案

遍历行中的表格单元格,并用文本输入替换内容:

function editRow(row) {$('td',row).each(function() {$(this).html('<input type="text" value="' + $(this).html() + '"/>');});}

显然需要将相关行/行传递给函数.

I have a table with arbitrary columns and rows. This fact is irrelevant though really, all I want to do is develop a function that will turn a row (or multiple rows) into a series of text inputs containing the data in the table (or empty if no data in cell).

I can't find any examples of people explicitly doing this, so I wondered what people here think is the best way to find a solution.

解决方案

Iterate over the table cells in the rows, and replace the contents with text inputs:

function editRow(row) {
    $('td',row).each(function() {
         $(this).html('<input type="text" value="' + $(this).html() + '" />');
    });
}

You need to pass the relevant row/rows into the function obviously.

这篇关于jQuery - 内联编辑表格行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆