这是我的JQuery代码绑定html表。我有两个图像...我如何检查const int Size = 4;
Mayonnaise[] mayonnaise;
Cheese[] cheese;
Flour[] flour;
Sugar[] sugar;
void Start()
{
mayonnaise = new Mayonnaise[Size];
cheese = new Cheese[Size];
flour = new Flour[Size];
sugar = new Sugar[Size];
//Create instance of of them
for (int i = 0; i < Size; i++)
{
mayonnaise[i] = new Mayonnaise();
cheese[i] = new Cheese();
flour[i] = new Flour();
sugar[i] = new Sugar();
}
mayonnaise[0].setHave(SomeTextComponent);
mayonnaise[0].getHave().text = "Some Text";
string text = mayonnaise[0].getHave().text;
}
true
显示何时以及1.jpg
false
显示的时间。
2.jpg
我正在拍摄$(function () {
debugger
$.ajax({
type: "POST",
contentType: "application/json; charset=utf-8",
url: "WebForm5.aspx/BindDatatable",
data: "{}",
dataType: "json",
success: function (dt) {
debugger;
for (var i = 0; i < dt.d.length; i++) {
$("#example1 > tbody").append("<tr><td> <input type='checkbox' class='chk' id=" + dt.d[i].CategoryID + " /></td><td>" + dt.d[i].CategoryID + "</td><td>" + dt.d[i].Name + "</td><td><input type='image'if() src='images/1.png'title='Deactivate this' value=" + dt.d[i].Status + " alt='Submit' width='18' height='18'> </td><td> <i class='ui-tooltip fa fa-pencil' onclick='btnQueryString_Click(" + dt.d[i].CategoryID + ")' style='font-size:22px;margin-left: 32px;'></i><i class='ui-tooltip fa fa-trash-o' onclick='deleteRecord(" + dt.d[i].CategoryID + ")' style='font-size: 22px;margin-left: 32px;'></i> </tr>");
}
$("#example1").DataTable();
},
error: function (result) {
alert("Error");
}
});
});
标记。
<input type='image'>
指导我如何检查状态值是真还是假以及如何在表状态列中显示它?
注意:如果我仅使用<input type='image' src='images/1.png'title='Deactivate this' value=" + dt.d[i].Status + " alt='Submit' width='18' height='18'>
,则表格中会显示OUTPUT + dt.d[i].Status +
或True
。
答案 0 :(得分:1)
首先,
</td>
if()
,这是无效的html '
替换为\'
,将"
替换为'
以保持格式不变所以,在你的for循环中加入这样的东西应该可行
var image='';
if( dt.d[i].Status == true ) {
image = '1.jpg';
}else{
image = '2.jpg';
}
var data = '<tr> <td> <input type=\'checkbox\' class=\'chk\' id=' + dt.d[i].CategoryID + ' /></td><td>' + dt.d[i].CategoryID + '</td> <td>' + dt.d[i].Name + '</td> <td><input type=\'image\' '+ image +' src=\'images/unblock.png\' title=\'Deactivate this\' value=' + dt.d[i].Status + ' alt=\'Submit\' width=\'18\' height=\'18\'> </td> <td> <i class=\'ui-tooltip fa fa-pencil\' onclick=\'btnQueryString_Click(' + dt.d[i].CategoryID + ')\' style=\'font-size:22px;margin-left: 32px;\'></i> <i class=\'ui-tooltip fa fa-trash-o\' onclick=\'deleteRecord(' + dt.d[i].CategoryID + ')\' style=\'font-size: 22px;margin-left: 32px;\'></i> </td></tr>';
$("#example1 > tbody").append(data);