【发布时间】:2018-08-28 10:53:01
【问题描述】:
我有一个类似下面的函数。
首先,我将所有课程更改为“徽章徽章辅助”。 然后,检查 span 中的文本。如果它是“正确的”并单击,则更改为“badge badge-primary”。 否则,它是“错误”并单击,更改为“class”,“badge badge-danger”。
我可以让我的代码更简洁正确吗?
function updateOrderType(ansType) {
lastAnsType = ansType;
var ansBadge = d3.select("#anstype").selectAll("span.badge");
ansBadge.attr("class", "badge badge-secondary");
ansBadge.filter(function() {
if (d3.select(this).text() == ansType) {
return d3.select(this).text() == "right";
}
}).attr("class", "badge badge-primary");
ansBadge.filter(function() {
if (d3.select(this).text() == ansType) {
return d3.select(this).text() == "wrong";
}
}).attr("class", "badge badge-danger");
}
【问题讨论】:
标签: javascript if-statement d3.js filter bootstrap-4