这是我的PHP:
class generate{
// PROJECT TABLE GENERATOR
public function genTable(){
global $data;
global $select;
global $pdo;
$result = $data->filterData();
echo '<table class="table">
<tbody>';
echo '<tr>
<th>heaer1</th>
<th>Header2</th>
<th>header3</th>
<th>header4</th>
<th>header5</th>
</tr>
<tr class="addForm">
<td>
<form action="parsers/parseData.php" method="post">
<label>Name</label>
<input type="text" id="Name">
<label>Purpose</label>
<input type="text" id="Purpose" >
</form>
</tr>';
foreach($result as $res){
echo '<tr data-id="' . $res['ID'] . '" ><td>' . $res['Name'] . '</td>
<td>' . $res['Purpose'] . '</td>
<td>' . $res['Owner'] . '</td>
<td>' . $res['Start'] . '</td>
<td>' . $res['End'] . '</td>
<td style="width:110px;"><button type="button" id="deleteBtn" class="btn btn-default" name="deleteBtn"><b class="glyphicon glyphicon-trash"></b></button>
<button type="button" id="editBtn" class="btn btn-default" name="editBtn"><b class="glyphicon glyphicon-pencil"></b></button>
</td>
</tr>
<tr data-id="' . $res['ID'] . '" class="hidden" id="editForm">
<td>
<form action="/" method="post">
<div class="form-group">
<input type="text" id="Name" placeholder="Name">
</div>
</td>
<td>
<div class="form-group">
<input type="text" id="Purpose" placeholder="Purpose">
</div>
</td>
<td>
';
$select->genSelect();
echo '
</td>
</form>
</tr>
';
}
echo '</form>
</tbody></table>';
}
...的jQuery
$('button#editBtn').click( function(){
var id = $(this).parents('tr').data('id');
var Formid = $(this).closest('tr[id=editForm]').removeClass('hidden');
console.log(Formid);
});
jQuery不起作用,我想要做的是选择 tr ,其中 id 的editForm等于 tr 在它之上,当我点击表格旁边的编辑按钮时,一个表格在按钮所在的行下面下降......是否可能?
我也尝试了这个,但它给出了 undefined
的回报 $('button#editBtn').click( function(){
var id = $(this).parents('tr').data('id');
var attrId = $('tr#editForm').parents().data("id");
console.log(attrId); });
哦,还有这个...
$(document).ready(function(e) {
$('tr#editForm').toggle(); });
当我选择正确的标签时,希望我能够再次切换它
答案 0 :(得分:1)
也许这可以帮到你。我无法通过你的代码找到错误,因为它有点乱,但我想我只是明白你的目标是什么。看看:
<? foreach($result as $res) { ?>
<table>
<tr id="<?= $res['ID'] ?>">
<td>Some information</td>
<td width="10%"><a class="edit">Edit</a></td>
</tr>
<tr id="editForm_<?= $res['ID'] ?>" class="hidden">
<td colspan="2">Edit Form</td>
</tr>
<tr id="<?= $res['ID'] ?>">
<td>Some information</td>
<td width="10%"><a class="edit">Edit</a></td>
</tr>
<tr id="editForm_<?= $res['ID'] ?>" class="hidden">
<td colspan="2">Edit Form</td>
</tr>
</table>
<? } ?>
$('.edit').click(function() {
var trID = $(this).closest('tr').attr('id');
$('tr#editForm_'+trID).fadeToggle();
});