html标签输入type =“number”和基于文化的小数分隔符 [英] html tag input of type=”number” and culture based decimal separator

查看:128
本文介绍了html标签输入type =“number”和基于文化的小数分隔符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我打开具有其他文化和UI(即瑞典)的网站以查看正确的小数点分隔符时,我需要的是英文浏览器。

What I need is in English browser when I open website that has another culture and UI (i.e. Sweden) to see the proper decimal separator.

如何存档?

  <input type="number" step="0.1"  pattern="[0-9]+([\,][0-9]+)?" min="0" max="5" />

如果我在下一次旋转浏览器时应用任何数字如0,1重置它到0.2,它有一个点而不是逗号。

If even I apply any number like "0,1" with the next click of spinner Browser reset it to "0.2" which has a dot instead of comma.

那么如何保持正确的小数点分隔符?

So how to keep proper decimal separator?

任何线索如何用jQuery修复它?

Any clue how to fix it with jQuery?

推荐答案

浏览器不支持HTML5数字输入分隔符,每个用户体验会因计算机区域设置而异。将分隔符强制为逗号可能不明智。

Browsers do not support HTML5 number inputs seperators very well and each users experience would differ based on their computers regional settings. It may not be wise to force the seperator to be a comma.

我能想到的唯一方法是使用javascript。以下是使用普通输入字段的一个示例。不幸的是,您将丢失与数字输入相关联的html5输入属性。

The only way I can think of is to use javascript. Here is one example using normal input field. Unfortunately you will lose the html5 input attributes associated with number inputs.

var Inputs = document.querySelectorAll('input');
for (var i=0; i<Inputs.length; i++) {
  Inputs[i].onblur = function() {
    this.value = this.value.replace('.',',');
  }
}

function multiplyAndPopulate() {
  var A1 = theForm.A1field.value.replace(',','.');
  var A2 = theForm.A2field.value.replace(',','.');
  var R1 = (A1*A2);
  if (isNaN(R1) == true) {
    alert('Invalid.');
    return false;
  }
  else {
    theForm.R1field.value = R1;
    theForm.R1field.value = theForm.R1field.value.replace('.',',');
  }
}

<input type="text" pattern="[0-9]+([\,][0-9]+)?" MaxLength="3"/>

这篇关于html标签输入type =“number”和基于文化的小数分隔符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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