如何强制显示带有输入类型编号的逗号的数字? [英] How to force to display a number with a comma with input type number?

查看:111
本文介绍了如何强制显示带有输入类型编号的逗号的数字?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这个输入类型编号:

I have this input type number:

<input type="number">

当然值是一个数字,如何强制它用逗号显示数字?并使其与大多数HTML 5浏览器兼容?

Of course the value is a number, how to force it to display a number with a comma? And make it compatible with most HTML 5 browsers?

我搜索但是我找不到解决方案。我输出了一个数字,但它没有显示逗号。

I searched but I didn't find a solution. I outputted a number but it is not showing with a comma.

推荐答案

您可以使用法语区域设置 lang =fr使用逗号作为小数分隔符。

You can use the french locale lang="fr" that use a comma for the decimal separator.

<!DOCTYPE html>
<html>
  <head>
    <meta charset="UTF-8">
    <title>Input test</title>
    <script>
      function init(){
        document.getElementById('in1').value = 3.14;
      }
    </script>
  </head>
  <body onload="init()">
    <input id="in1" lang="fr" type="number">
  </body>
</html>

适用于Firefox 39.0:

It works well with Firefox 39.0:

但不幸的是,它还没有在Chrome 44中实现。

but unfortunately it's not yet implemented in Chrome 44.

这篇关于如何强制显示带有输入类型编号的逗号的数字?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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