您好我想要执行更新功能,其中每个员工余额都列在表格的一行中。提交表单时,它只会提交特定的行。这样的事情。
我是jquery的新手,有人可以指点我吗?
<table id="rounded-corner">
<thead>
<tr>
<th scope="col" class="rounded-company">Name</th>
<th scope="col" class="rounded">Position</th>
<th scope="col" class="rounded">Annual Leave Balance</th>
<th scope="col" class="rounded">Sick Leave Balance</th>
<th scope="col" class="rounded">Action</th>
</tr>
</thead>
<tbody>
<?php foreach($list as $value) {?>
<tr id='<?php echo $value['IDSTAFFTABLE']; ?>'>
<td><?php echo $value['FIRSTNAME']; ?> <?php echo $value['LASTNAME']; ?></td>
<td><?php echo $value['POSITIONNAME']; ?></td>
<td><input type="text" name="annualleave" class="annualleave" value="<?php echo $value['ANNUALLEAVE']; ?>"/></td>
<td><input type="text" name="sickleave" class="sickleave" value="<?php echo $value['SICKLEAVE']; ?>"/></td>
<td><input type="submit" name="submit" class="submit" value="Submit" /></td>
</tr>
<?php } ?>
</tbody>
答案 0 :(得分:0)
首先在php foreach循环中为你的html代码添加一个表单,就像这样...
<!-- Making use of foreach...endforeach is much better -->
<!-- when using annotated php code in html -->
<?php foreach($list as $value): ?>
<form action="something" method="post">
<!-- Rest of the code remains same -->
</form>
<?php endforeach; ?>
然后使用此jquery提交特定表单...
$('input.submit').click( function() {
$(this).parent("form").submit();
});
只要按下“submit”类的输入,此代码就会触发一个click事件, 它将提交其父表格。