选择表中仅有1行我有一个创建的表在哪里显示多个records..I要添加使用Ajax更新功能..如何从使用jQuery
我写了下面的代码,当我点击在任何行上,它使所有行都可编辑。我只想编辑我点击的特定行。
请亲引导我如何做到这一点。
<button type="button"
class="updateUser btn btn-primary btn-xs" data-userId="<?php echo $id; ?>">
<span class="glyphicon glyphicon-pencil"></span>
</button>
$(document).on("click", ".updateUser", function(){
$('tr td:nth-child(2)').each(function() {
var html = $(this).html();
var input = $('<input type="text" />');
input.val(html);
$(this).html(input);
});
});
编辑 - HTML代码
<table class="table table-hover">
<thead>
<tr>
<th>#</th>
<th>Username</th>
<th>Password</th>
<th>Role</th>
<th>Edit</th>
<th>Delete</th>
</tr>
</thead>
<tbody>
<tr>
<td>"PHP Dynamic ID "</td>
<td>"PHP Dynamic Username "</td>
<td>"PHP Dynamic Password "</td>
<td>"PHP Dynamic Role "</td>
<td>
<button type="button" class="updateUser btn btn-primary btn-xs" data-userId="<?php echo $id; ?>">
<span class="glyphicon glyphicon-pencil"></span>
</button>
</td>
<td>
<button class="deleteUser btn btn-danger btn-xs" type="button" data-userId="<?php echo $id; ?>">
<span class="glyphicon glyphicon-remove"></span>
</button>
</td>
</tr>
</tbody>
</table>
如果您发布的HTML代码,这将有助于更好的是,一个的jsfiddle。 –