最近,我恰好来到了这个页面。
我意识到代码的变化发生在这个函数中。
它从 <tr><td>A</td><td>1</td><td style="background-color:#336699"> </td></tr>
中获取数据.
如果<td>
中的数据是整数,它不像 % 那样有太大的影响。
如何让它接受整数并提供类似于 % 的效果?
function viewGraph() {
$(".column").css("height", "0");
$("table tr").each(function(index) {
var ha = $(this).children("td").eq(1).text();
$("#col" + index)
.animate({ height: ha }, 1500)
.html("<div>" + ha + "</div>");
});
}
$(document).ready(function() {
viewGraph();
});
最佳答案
只需将它添加到您的代码中,它就会按照您希望的方式工作
if(!ha.includes("%")) {
ha = ha + "%";
}
应用于您的代码:
function viewGraph() {
$(".column").css("height", "0");
$("table tr").each(function(index) {
var ha = $(this).children("td").eq(1).text();
// Simply add this.
if(!ha.includes("%")) {
ha = ha + "%";
}
$("#col" + index)
.animate({ height: ha }, 1500)
.html("<div>" + ha + "</div>");
});
}
$(document).ready(function() {
viewGraph();
});
希望这对你有所帮助。
关于javascript - 如何在此代码笔中更改为整数而不是 %,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44380903/