参见我的交叉浏览器 < a href=>“https://github.com/anhr/InputKeyFilter” rel=“不跟随 noreferrer” 代码, 用户可以根据用户系统设置将点或逗号输入为小数分隔符。
<!doctype html>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
<title>Input Key Filter Test</title>
<meta name="author" content="Andrej Hristoliubov [email protected]">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<!-- For compatibility of IE browser with audio element in the beep() function.
https://www.modern.ie/en-us/performance/how-to-use-x-ua-compatible -->
<meta http-equiv="X-UA-Compatible" content="IE=9"/>
<link rel="stylesheet" href="https://rawgit.com/anhr/InputKeyFilter/master/InputKeyFilter.css" type="text/css">
<script type="text/javascript" src="https://rawgit.com/anhr/InputKeyFilter/master/Common.js"></script>
<script type="text/javascript" src="https://rawgit.com/anhr/InputKeyFilter/master/InputKeyFilter.js"></script>
</head>
<body>
Float field:
<input type="number" step="any" id="Float"
onchange="javascript: onChangeFloat(this)"
onblur="inputKeyFilter.isNaN(parseFloat(this.value), this);"
/>
<script>
CreateFloatFilter("Float");
function onChangeFloat(input){
inputKeyFilter.RemoveMyTooltip();
var elementNewFloat = document.getElementById("NewFloat");
var float = inputKeyFilter.parseFloat(input.value);
if(inputKeyFilter.isNaN(float, input)){
elementNewFloat.innerHTML = "";
return;
}
elementNewFloat.innerHTML = float + " or localized value: " + float.toLocaleString();
}
</script>
New float: <span id="NewFloat"></span>
</body>
</html>
感谢>Dr.Oblak ss 回答,我怎么知道客户使用哪个小数分隔器?
另见我的网页“https://anhr.github.io/InputKeyFilter/' rel=“不跟随 nofollow noreferrer'”>输入键过滤器 的示例。