HTML-格式化数据输入字段中的小数位 [英] HTML - formatting decimal places in data entry fields

查看:611
本文介绍了HTML-格式化数据输入字段中的小数位的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

发疯并花费大量时间试图使输入字段显示带有尾随零的数字.

Going crazy and spending a lot of time trying to get input fields to display numbers with trailing zeros.

在显示数据库中的数据时或在某人编辑字段后,我希望显示3个小数位.

I want 3 decimal places to be shown when presenting data from the database, or after someone edits the field.

因此,如果有人输入"2.34",我希望输入"2.340".显示(在他们跳出字段或保存之后)

So, if someone enters "2.34", I want "2.340" to display (after they tab out of field or save)

我已经尝试过postRender"toFixed"其他帖子中的建议,例如:https://msdn.microsoft.com/en-us/library/jj733572.aspx#Format

I've tried the postRender "toFixed" suggestions in other posts such as: https://msdn.microsoft.com/en-us/library/jj733572.aspx#Format

我也将文本转换为数字或浮点数,然后又返回.

I've also converted text to number or floats and back again.

它不起作用.某种东西正在消除尾随的零.

It's not working. Something is taking away the trailing zeroes.

我确实发现,如果我使用完全相同的逻辑并更改了"displayName",页面上的数字(只是因为在测试时很容易看到),所以正确显示了该数字,但未正确显示在表单区域中.

I did find that if I used the exact same logic and changed the "displayName" of the page (just because it was easy to see when testing), that the number shows up correctly, yet it doesn't show up in the form area correctly.

这有效:

var textValue = parseFloat(value).toFixed(3);
contentItem.screen.details.displayName =>" + textValue +<";

var textValue = parseFloat(value).toFixed(3);
contentItem.screen.details.displayName = ">" + textValue + "<";

这不是:

contentItem.screen.myScreen.TestValue = parseFloat(value).toFixed(3);

contentItem.screen.myScreen.TestValue = parseFloat(value).toFixed(3);

这也不是:

And neither does this:

var textValue = parseFloat(value).toFixed(3);
contentItem.screen.myScreen.TestValue = textValue;

var textValue = parseFloat(value).toFixed(3);
contentItem.screen.myScreen.TestValue = textValue;

(在postRender函数中)也没有:

And neither does this (in a postRender function):

  $(element).text(value.toFixed(3));

有人对此有解决方案吗?这是一个基本的用户界面,应该不难做到.

Anyone have a solution for this? This is a basic user interface thing that shouldn't be this hard to do.

谢谢

戴夫

推荐答案

在尝试手动调整时,尝试将更改行包装在setTimeout({},0)调用中任何显示属性.这样可以确保在所有其他postRender代码对屏幕进行更改(可能会影响 您尝试更改的字段,即使您认为与此没有任何关系.在那之后通常可以正常工作.

Try wrapping the changing line inside a setTimeout({},0) call whenever you're trying to manually adjust any display properties. That ensures that it doesn't execute until all of the other postRender code has made changes to the screen that might affect the field you're trying to alter, even if you think nothing else is related to it. It usually works just fine after that.

此致

RT Watkins

RT Watkins


这篇关于HTML-格式化数据输入字段中的小数位的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆