Php Jquery选择标记,其中其数据id attr=具有相同数据id的另一个标记
以下是我的PHP:Php Jquery选择标记,其中其数据id attr=具有相同数据id的另一个标记,php,jquery,html-table,Php,Jquery,Html Table,以下是我的PHP: class generate{ // PROJECT TABLE GENERATOR public function genTable(){ global $data; global $select; global $pdo; $result = $data->filterData(); echo '<table class="table">
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不太管用,我要做的是选择id为editForm的tr,它等于它上面的tr,这样当我在表中单击它旁边的edit按钮时,一个表单就会从按钮所在行的下面掉下来。。。可能吗
我也尝试过,但它的返回值未定义
哦,还有这个
$(document).ready(function(e) {
$('tr#editForm').toggle(); });
当我选择正确的标签时,希望我能够再次切换它也许这可以帮助您。我不想费心去检查你的代码来找出错误,因为它有点混乱,但我想我已经大致理解了你的目标。看一看:
<? 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();
});
如果您发布呈现的html而不是难看的PHP codeconsider.attr('data-id')
您的id为editRow的tr
位于foreach
循环中,则更容易提供帮助,因此多行具有相同的id!ID必须是唯一的。这绝对是个问题。
$(document).ready(function(e) {
$('tr#editForm').toggle(); });
<? 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();
});