Slick 滑块中的两位数字而不是点
Two digit numbers instead of dots in Slick slider
我想在滑块中使用数字而不是点。
为此,我使用了以下代码:
$('slider').slick({
dots: true,
appendDots: $('slider-dots'),
customPaging : function(slider, i) {
var thumb = $(slider.$slides[i]).data();
return '<a>'+(i+1)+'</a>';
},
arrows: false,
slidesToShow: 1,
slidesToScroll: 1,
}
有什么方法可以将数字从一位数更改为两位数。
例如:01 02 03
您要找的方法是padStart。这会将一些字符串的填充添加到另一个字符串的开头。
(0).toString().padStart(2, '0') // Result: '00'
(1).toString().padStart(2, '0') // Result: '01'
'5'.padStart(2, '0') // Result: '05'
(10).toString().padStart(2, '0') // Result: '10'
'100'.padStart(2, '0') // Result: '100'
所以,在你的情况下你会使用这个:
(i+1).toString().padStart(2, '0')
您需要使用 toString()
才能在数字上使用 padStart()
,除非该数字是字符串化数字。
我想在滑块中使用数字而不是点。 为此,我使用了以下代码:
$('slider').slick({
dots: true,
appendDots: $('slider-dots'),
customPaging : function(slider, i) {
var thumb = $(slider.$slides[i]).data();
return '<a>'+(i+1)+'</a>';
},
arrows: false,
slidesToShow: 1,
slidesToScroll: 1,
}
有什么方法可以将数字从一位数更改为两位数。 例如:01 02 03
您要找的方法是padStart。这会将一些字符串的填充添加到另一个字符串的开头。
(0).toString().padStart(2, '0') // Result: '00'
(1).toString().padStart(2, '0') // Result: '01'
'5'.padStart(2, '0') // Result: '05'
(10).toString().padStart(2, '0') // Result: '10'
'100'.padStart(2, '0') // Result: '100'
所以,在你的情况下你会使用这个:
(i+1).toString().padStart(2, '0')
您需要使用 toString()
才能在数字上使用 padStart()
,除非该数字是字符串化数字。