我想附加一个带有某个类名的span。我使用JavaScript MAP 来获取类名。这样它就可以附加相应的类名。
我可以使用以下方法获取值:
mymap.get(value.status)
但我是,但我无法传递类名称,如:
<span class...
function refresh() {
var $table = $("table#mytable");
$.getJSON("//127.0.0.1:8001/get_latest_verification", function (obj) {
$.each(obj, function (key, value) {
var mymap = new Map();
mymap.set('Registered', 'badge badge-info');
mymap.set('Tampered', 'badge badge-important');
mymap.set('Verified', 'badge badge-success');
mymap.set('Void', 'badge badge-inverse');
mymap.set('Released', 'badge badge-inverse');
var state = mymap.get(value.status)
var rows = "";
rows = rows + "<tr>" + "<td>" + value.asset_code + "</td>" + "<td>" + value.scan_time + "</td>" + "<td>" + value.credential + "</td>" + "<td>" + "<span class='state'>" + value.status + "</span>" + "</td>" + "<td>" + value.operator + "</td>" + "<td>" + value.location + "</td>" + "<td>" + value.auth_code + "</td>" + "<td>" + value.emp_id + "</td>" + "</tr>";
$table.prepend(rows);
});
});
}
答案 0 :(得分:2)
您必须使用字符串连接来添加类属性值,因为state
是一个包含类名的变量
"<span class='" + state + "'>"
而是"<span class='state'>"
创建带有类state