我在引导程序交互式表格的每一行都有一个编辑按钮。我正在尝试切换按钮图形,并根据其当前状态,使相应的行可编辑。无法使用JQuery编辑多行
<td><button type="button" id="edit" value="" class="btn btn-lg btn-link" data-toggle="tooltip" title ="Edit" style="color: black"><i class="glyphicon glyphicon-edit"></i></td>
和Java脚本如下
$(document).ready(function() {
$("#edit").click(function() {
var currentTD = $(this).parents('tr').find('td');
if($(this).find('i').hasClass('glyphicon-edit'))
{
currentTD = $(this).parents('tr').find('td');
$.each(currentTD, function() {
$(this).prop('contenteditable', true);
$(this).css('background','yellow');
});
}
else if($(this).find('i').hasClass('glyphicon-ok-circle'))
{
$.each(currentTD, function() {
$(this).prop('contenteditable', false);
$(this).css('background','');
});
}
$(this).find('i').toggleClass('glyphicon-edit').toggleClass('glyphicon-ok-circle');
})
});
的问题是,我只能做到这一点的第一行。我不知道为什么会发生这种情况。网络新东西在这里。 谢谢!
因为你使用的是ID,它只能针对一个元素。使用类选择器,使多个按钮有针对性 – user1