Java 脚本 onkeyDown 替换字符函数在 Internet Explorer 9 上无法正常工作
我有一个用于十进制数字的 asp 文本框。 我有一个 jscript 函数来替换数字键盘“。”用户区域性中使用的小数分隔符的字符(例如:en-US -> 小数分隔符:“.” pt-PT -> 小数分隔符:',')
这是我的功能:
//method that substitutes num pad '.' with the current user culture decimal separator when num pad '.' key is hit
function onKeyDownPutDecimalSeparator(e, textBox) {
var unicode = e.charCode ? e.charCode : e.keyCode;
if (unicode == 110) {
e.returnValue = false;
e.cancel = true;
textBox.value = textBox.value.concat(decimalSeparator);
}
}
这在大多数浏览器上运行良好,包括chrome和IE8,但在IE9中而不是 替换,例如1.2-> 1,2, 正在做类似的事情:
1.2 -> 1,.2,当文本框失去焦点时,1,2
最终值“1,2”就是我想要的,但是当用户实际看到“1,.2”时,中间步骤就太糟糕
了那?
谢谢
I have an asp text box for decimal numbers.
I have a jscript function to replace the num pad "." character by the decimal separator used in the user culture(ex: en-US -> decimal separator: "." pt-PT -> decimal separator: ',')
here's my function:
//method that substitutes num pad '.' with the current user culture decimal separator when num pad '.' key is hit
function onKeyDownPutDecimalSeparator(e, textBox) {
var unicode = e.charCode ? e.charCode : e.keyCode;
if (unicode == 110) {
e.returnValue = false;
e.cancel = true;
textBox.value = textBox.value.concat(decimalSeparator);
}
}
this is working fine on most browsers, including chrome and IE8, but in IE9 instead of
replacing, for ex. 1.2 -> 1,2,
is doing something like:
1.2 -> 1,.2 and when the text box looses focus, 1,2
the final value "1,2" is what i want, but that middle step when the user can actually see "1,.2" it's just awfull
any tip on that?
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
而不是
尝试
Instead of
Try