【发布时间】:2019-01-06 18:29:06
【问题描述】:
我想根据 if else 条件更改我的 ajax 按钮。就像状态为 1 一样,它只会显示活动按钮,否则只会显示非活动按钮。我有两个按钮。我找不到我实际放置 if else 条件的逻辑。我的代码是:
function showAllArticle(status = "") {
//alert(status);
$.ajax({
//cache: false,
//headers: { "cache-control": "no-cache" },
type: 'ajax',
method: 'post',
data: {
status: status
},
url: '<?php echo base_url() ?>Article/showAllUser',
async: true,
dataType: 'json',
//cache: false,
success: function(data) {
var html = '';
var i;
for (i = 0; i < data.length; i++) {
//(data[i].status);
html += '<tr>' +
'<td>' + data[i].id + '</td>' +
'<td>' + data[i].username + '</td>' +
'<td>' + data[i].email + '</td>' +
'<td>' +
// '{% if data[i].status == 1 %}'
'<a href="javascript:;" class="btn btn-info item-active" data="' + data[i].id + '">Active</a>' +
//@if(data[i].status == 1)
//'{% else %}'
'<a href="javascript:;" class="btn btn-danger item-inactive" data="' + data[i].id + '">Inactive</a>' +
//'{% endif %}'
/* '</td>' +
'<td>'+
'+@if(data[i].status == 1)+'
'tseting'+
'+@elseif(data[i].status == 0)+'
'debug'+
'+@endif+'
'</td>'+*/
'</tr>';
}
$('#showdata').html(html);
},
error: function() {
alert('Could not get Data from Database');
}
});
}
【问题讨论】:
-
根据代码 cmets,看起来您确切地知道将条件放在哪里。您只需要使用 Javascript 而不是任何看起来是的模板语言来完成。
标签: javascript php html ajax codeigniter