IE8 及之前的 javascript/ jquery 焦点问题
我有一个小问题。
目前,我有以下函数用于在输入文本字段的焦点/模糊上格式化货币:
$('.number').bind({
focus: function() {
$(this).val('$' + $(this).val());
},
blur: function() {
var defVal = $(this)[0].defaultValue;
var dollars = $(this).val();
dollars = dollars.replace('$', '');
dollars = dollars.replace(',', '');
dollars = parseFloat(dollars).toFixed(2);
if (!(isNaN(dollars))) {
$(this).val(dollars);
} else {$(this).val(defVal).removeClass('inpt_validBlur');};
}
});
这在 Firefox、Safari 和 IE9 中可以正常工作,但在 IE 的早期版本中存在问题。在 IE 中,当您开始输入时,您的文本出现在美元符号之前,而不是之后。有谁知道其原因以及如何解决它?
谢谢
I have a small problem.
currently, I have the following function for formatting currency on the focus/blur of an input text field:
$('.number').bind({
focus: function() {
$(this).val('
This works just as desired in Firefox, Safari, and IE9, but in prior versions of IE there is an issue. in IE, when you start typing, your text comes BEFORE the dollar sign, not after. Does anyone know the reason for this and how to get around it?
Thank you
+ $(this).val());
},
blur: function() {
var defVal = $(this)[0].defaultValue;
var dollars = $(this).val();
dollars = dollars.replace('
This works just as desired in Firefox, Safari, and IE9, but in prior versions of IE there is an issue. in IE, when you start typing, your text comes BEFORE the dollar sign, not after. Does anyone know the reason for this and how to get around it?
Thank you
, '');
dollars = dollars.replace(',', '');
dollars = parseFloat(dollars).toFixed(2);
if (!(isNaN(dollars))) {
$(this).val(dollars);
} else {$(this).val(defVal).removeClass('inpt_validBlur');};
}
});
This works just as desired in Firefox, Safari, and IE9, but in prior versions of IE there is an issue. in IE, when you start typing, your text comes BEFORE the dollar sign, not after. Does anyone know the reason for this and how to get around it?
Thank you
这似乎对我有用。并不完美,而且我不太喜欢混合 javascript 和 jquery,但它确实有效。
this seems to be working for me. Not perfect, and I dont really like mixing javascript and jquery, but it works.