Modificamos una función Meouw para usar con la tecla, ya que cuando usa una entrada puede ser más útil.
Comprobar esto:
Hola !, @heridev y creó una pequeña función de jQuery.
Puede probar la próxima:
HTML
<input type="text" name="one" class="two-digits"><br>
<input type="text" name="two" class="two-digits">
jQuery
// apply the two-digits behaviour to elements with 'two-digits' as their class
$(function() {
$('.two-digits').keyup(function(){
if($(this).val().indexOf('.')!=-1){
if($(this).val().split(".")[1].length > 2){
if(isNaN(parseFloat(this.value))) return;
this.value = parseFloat(this.value).toFixed(2);
}
}
return this; //for chaining
});
});
demostración en línea:
http://jsfiddle.net/c4Wqn/
(@heridev, @vicmaster)
Hola, me gustaría saber si necesitamos otro complemento para currencyFormat()? .. –
¿Funciona esto en IE? Lo tengo trabajando en Chrome y FF pero no en IE ... – Rexxo