Jquery UI 滑块 - 输入值截断 3.40 -> 3.4

发布于 2024-08-04 02:57:34 字数 211 浏览 6 评论 0原文

我正在尝试解决一个问题。当我加入步进时,可以说 0.01 一切都很好。但是,如果它落在 1 上,则会打印 1 而不是 1.00,并且 3.40 会打印为 3.4。

我已在 ui.slider.js 的各个位置添加了 toFixed(2),但尚未找到进行此修复的正确位置。

任何人都可以阐明这个问题。

此致, 罗伯特·库欣 开发商: Brilliance.com

I am trying to resolve an issue. When I put in stepping, lets say .01 everything works great. However, if it lands on 1 it prints 1 instead of 1.00, as well as 3.40 prints as 3.4.

I have added toFixed(2) in various places of ui.slider.js, but have not found the correct location to make this fix.

Can anyone shed light to this question.

Best Regards,
Robert Cushing
Developer: Brilliance.com

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

烛影斜 2024-08-11 02:57:34

如果我理解你的问题,你想查询滑块的值并以特定格式将其显示在其他地方(滑块不会在任何地方显示该值)。注入格式化逻辑的时间点是在查询滑块之后并将其显示在其他地方之前(注意:这意味着您不编辑 ui.slider.js)。类似于:

var value = $('#my-slider').slider('value');
var formattedValue = value.toFixed(2);
$('#my-span').text('Current Value: ' + formattedValue);

如果您尝试在滑块 change 事件中执行此操作,则当前值将作为函数的参数提供给您。例子:

$('#my-slider').slider({
    change: function(event, ui) {
        var formattedValue = ui.value.toFixed(2);
        $('#my-span').text('Current Value: ' + formattedValue);
    }
});

If I understand your question, you want to query the value of a slider and display it somewhere else in a specific format (the slider doesn't display the value anywhere). The point where you inject your formatting logic is after you query the slider and before you display it somewhere else (note: this means you do NOT edit ui.slider.js). Something like:

var value = $('#my-slider').slider('value');
var formattedValue = value.toFixed(2);
$('#my-span').text('Current Value: ' + formattedValue);

If you're attempting to do this inside the sliders change event, then the current value is provided to you as a parameter of your function. Example:

$('#my-slider').slider({
    change: function(event, ui) {
        var formattedValue = ui.value.toFixed(2);
        $('#my-span').text('Current Value: ' + formattedValue);
    }
});
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文