JavaScriptで数字の桁数を揃える
- 2019.01.21
- Coding JavaScript
- 桁, 桁揃え
$(function() {
$('#number li').each(function() {
var digit = 3; // 桁数の指定
var no = $(this).text();
while(no.length < digit) {
no = '0' + no;
}
$(this).text(no);
});
});
参考サイト
-
前の記事
yoast SEOでPrimaryに設定したカテゴリー名を表示する 2018.12.26
-
次の記事
vue.jsでbuttonのdisabledを切り替える 2019.01.22