jquery + table row edit – 字符串问题

我编辑一行有一个问题…我想用一个按钮进入表格中的编辑模式(从php数组生成(从mysql获取的数据))

每个数据我有两行:

 id; ?> pl>0 ? '
' . $row->pl .'
' : '
' . $row->pl . '
';?>
reason;?>
comment;?>
cdate; ?>
ctime; ?>
mdate; ?>
mtime; ?>
<form id="id;?>"> id; ?><input type="hidden" name="id" id="id" value="id;?>" /> <input type="text" id="pl" name="pl" value="pl;?>" />
cdate; ?>
ctime; ?>
mdate; ?>
mtime; ?>

我附上了两个jquery语句……

1。 一个…将行更改为

  $("#editlink").click(function() { var datapos = $(this).parent().parent().prevAll().length; var editpos = datapos + 1; $("#data_table tbody tr:eq(" + datapos + ")").hide(); $("#data_table tbody tr:eq(" + editpos + ")").show(); }); 

完美的工作。

第2位。 假设在完成更改后保存(POST到PHP脚本)并重新加载页面。

  $("#edit_save").click(function() { var dataString = $("form").serialize(); var editpos = $(this).parent().parent().prevAll().length; var datapos = editpos - 1; $.ajax({ type: "POST", url: "edit", data: dataString, success: function() { $("#lightbox").fadeIn(900); $("#notification-box").show(); $("#notification-box").html("<img src='https://stackoverflow.com/questions/3642310/jquery-table-row-edit-string-problem/img/notification.gif'>

Saving

"); location.reload(); } }); });

所以,我在这里遇到的问题是dataString是表中生成的所有值的值,而不是我想要编辑的特定行。

如果有人可以帮助我,我会很高兴。

干杯,

/亚切克

$("form")将获取页面中的所有

元素,您需要单击的按钮父窗体: $(this).parent('form')

 var dataString = $(this).parent('form').serialize();