5

有没有办法使用 html5 数字输入类型同时允许逗号和点作为分隔符?我找到了小数分隔符属性,但它似乎只需要一个分隔符......

4

2 回答 2

0

No 两者都不能用于 html5 数字输入类型。事实上,它可以支持十进制或浮点数以及实数。

于 2012-05-25T11:17:47.960 回答
0

请参阅我的跨浏览器InputKeyFilter代码示例,其中用户可以输入点或逗号作为小数分隔符,具体取决于用户的系统设置。

<!doctype html>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
    <title>Input Key Filter Test</title>
	<meta name="author" content="Andrej Hristoliubov anhr@mail.ru">
	<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在 With a browser 中的回答,我如何知道客户端使用哪个小数分隔符?

另请参阅我的输入键过滤器页面示例

于 2015-08-07T14:24:26.077 回答