gpt4 book ai didi

javascript - 拖动范围 slider - 如何向输出添加步骤和元素(逗号)

转载 作者:行者123 更新时间:2023-11-30 10:14:58 24 4
gpt4 key购买 nike

我正在使用 dragdealer.js这是我到目前为止所得到的:

Fiddle

拖动幻灯片时,它会给出一个输出,

问题:1) 如何在拖动时在数百个单位后的输出中添加“,”(逗号)?

-> Right now:-$ 4023
-> Required Output:- $ 4,023

2) 如何实现 step 以显示输出是 100 的倍数?

-> Required Output:- $ 4.100 (multiple of 100)

这是我的代码:

JS:

$(function() {

new Dragdealer('just-a-slider', {
animationCallback: function(x, y) {
$('#dragValue').text(Math.round(x * 15000));
}
});

var availHeight = $('.content-body').outerHeight() -
$('.content-mask').outerHeight();
new Dragdealer('content-scroller', {
horizontal: false,
vertical: true,
yPrecision: availHeight,
animationCallback: function(x, y) {
$('.content-body').css('margin-top', -y * availHeight);
}
});
});

最佳答案

您可以使用 .replace(/(\d)(?=(\d\d\d)+(?!\d))/g, "$1,") 添加在逗号中,如果将您的基数除以 100,( = 150),您将步进 100,并可以根据需要在文本输出中附加额外的 0。

在这里查看 fiddle :http://jsfiddle.net/535Pd/4/

关于javascript - 拖动范围 slider - 如何向输出添加步骤和元素(逗号),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24385718/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com