是否有办法在表格的每一行上打印HTML表单,使表单具有该特定的行ID。
我有一个php for循环。 for循环从数据库中获取数据并将其放入表中。表格的每一行都有一个按钮。当我们点击按钮时,会出现一个表单。但问题是,无论我点击哪个行按钮,每个表单都会有相同的行ID。样本图片如下:
有人告诉我在点击事件中使用data-id =“”然后使用$(this).attr('data-id'),但我不确定如何使用
我的代码:
<thead>
<tr>
<th class="active1">ID</th>
<th>Title</th>
<th>Description</th>
<th>Critility</th>
<th>Priority</th>
<th>Date Submitted</th>
<th>Submittions</th>
</tr>
</thead>
<?php
foreach($results as $data){
echo '<tbody>
<div class="tryinglift"><tr class="dropDown">
<td><div class="bn">#'.$data['NO'].'</div></td>
<td><div class="titleInTable truncatee">'.$data['Title'].'<div></td>
<td><div class="truncate">'.$data['Description'].'</div></td>
<td><div class="c">'.$data['criticality'].'</div></td>
<td><div class="c">'.$data['Priority'].'</div></td>
<td>'.$data['Date_Submitted'].'</td>
<td><button class="showPop" class="btn btn-primary btn-small">SUBMIT</button></td>
</tr></div>
<div id="overlay"></div>
<div id="specialBox">
<form action="php/inbetween.php" method="POST" class="submittion_from">
<fieldset class="removeGender1">
<label>NO</label>
<label >YES</label>
</fieldset><br>
<input type="text" name="id" value='.$data['no'].'>
<fieldset class="removeGender">
<label>xyz questions</label>
<input type="radio" name="optradio" value="NO">
<input type="radio" name="optradio" value="YES">
</fieldset><br>
<fieldset class="removeGender">
<label>xyz questuion</label>
<input type="radio" name="optradio1" value="NO">
<input type="radio" name="optradio1" value="YES">
</fieldset><br>
<fieldset class="removeGender">
<label>xyz questions</label>
<input type="radio" name="optradio2" value="NO">
<input type="radio" name="optradio2" value="YES">
</fieldset><br>
<input type="submit" value="SUBMIT" id="no">
</form>
<button class="closePop">Close Overlay</button>
</div>
</tbody>';
echo '<div id="style1">
<div>'.$data['Description'].'</div>
</div>';
}
?>
我的jQuery:
$(".showPop").click(function(){
$("#overlay").css({"display":"block"});
$("#specialBox").css({"display":"block"});
});
$(".closePop").click(function(){
$("#overlay").css({"display":"none"});
$("#specialBox").css({"display":"none"});
});