如何正确对齐我的列状态数据?当我更新数据时,它不会像第一张图片那样对齐。
$('#btn_edit').click(function(){
var brand_id = $('#brand_id').val();
var brand_name = $('#brand_name').val();
var brand_status = $('#brand_status').val();
$.ajax({
url : 'edit_brand.php',
method : 'POST',
data : {brand_name : brand_name, brand_status : brand_status, brand_id : brand_id},
success : function(response) {
$('#'+brand_id).children('td[data-target=brand_name]').text(brand_name);
if (brand_status == "Available") {
$('#'+brand_id).children('td[data-target=brand_status]').replaceWith("<span class='label label-success'>Available</span>");
} else {
$('#'+brand_id).children('td[data-target=brand_status]').replaceWith("<span class='label label-danger'>Not Available</span>");
}
$('#modal-edit').modal('toggle');
}
});
答案 0 :(得分:0)
您正在用span替换td,尝试替换td内容,如下所示:
$('#'+brand_id).children('td[data-target=brand_status]').html(brand_status == "Available" ? "<span class='label label-success'>Available</span>" : "<span class='label label-danger'>Not Available</span>");
编辑:小编辑,你现在可以替换整个if-else块;)