我有一个表,其中的行由foreach循环生成。
每个表格行都有两列,一列是表单,另一列是表单提交的数据,我称之为注释。(以及使用 jQuery 库进行更新,而无需刷新浏览器)。
<script>
$(".notes_column").each(function(){
var $myform = $(this).find('.notes_form');
var $mynotes = $(this).find('.notes');
$myform.validate({
submitHandler: function(form) {
$.post('process.php', $myform.serialize(), function(data) {
$mynotes.html(data);
});
}
});
}); // each function
</script>
<table id="myTable" class="tablesorter" border="1" cellpadding="5">
<thead>
<tr>
<th>Notes</th>
<th>Submit Note</th>
</tr>
</thead>
<tbody>
<?php
foreach($myarray as $myvar){
echo '
<tr>
<td>ID LIKE TO PLACE THE content of the div class="notes" HERE, HOW CAN I DO IT?</td>
<td class="notes_column">
<form class="notes_form" action="" method="post">
<input class="q" type="text" name="notes" size="30" placeholder="Place your notes here..." />
<input class="searchsubmit" type="submit" name="submit" value="Submit" />
</form>
<div class="notes"></div>
</td>
</tr>
';
}
?>
</tbody>
</table>
现在我使用一个jQuery每个函数来迭代每个表列,并且对于每个类名为".notes_column"的列,使用提交的数据的类"notes"填充一个div。
问题以大写字母列在代码中,如何使用表单提交的数据填充另一列?
有什么想法吗?
泰
I would create a <div> in the first <td> such as
<td>
<div class="put_notes_here">ID LIKE TO PLACE THE content of the div class="notes" HERE, HOW CAN I DO IT?</div>
</td>
Then populate it the same as you did before
$mynotes.closest("tr").find(".put_notes_here").html(data);
将每个选择器更改为 $('#myTable tr'),然后您可以遍历表中的每一个。
然后你可以在 tr 对象上做一个 each 来访问每个 td,或者在后续选择器中使用 jQuery 的 :first-child 和 nth-child(2) 等