Maskmoney c/ Jquery or Javascript

Asked

Viewed 2,067 times

0

How to create a mask for Real R$ values? I tried to use http://plentz.github.io/jquery-maskmoney/ but I was unsuccessful.

I need a mask that introduces me to something like this: R$ 0,01 R$ 0,10 R$ 1,00 R$ 10,00 R$ 100,00 R$ 1,000,00 Something like this!!!

2 answers

1

Use Maskmoney this way:

Press jQuery and Maskmoney on the page:

<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery-maskmoney/3.0.2/jquery.maskMoney.min.js"></script>

Add the class .mascara to inputs that you want to create the mask:

<input type="text" class="mascara" />

Launch the plugin:

<script>
$(function(){
   $(".mascara").maskMoney({
      prefix: 'R$ ',
      allowNegative: true,
      thousands: '.',
      decimal: ','
   });
});
</script>

Example:

$(function(){
   $(".mascara").maskMoney({
      prefix: 'R$ ',
      allowNegative: true,
      thousands: '.',
      decimal: ','
   });
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery-maskmoney/3.0.2/jquery.maskMoney.min.js"></script>
<input name="valor1" type="text" class="mascara" >
<br />
<input name="valor2" type="text" class="mascara" >

-2

try using the code below:

$("#demo3").maskMoney({prefix:'R$ ', allowNegative: true, thousands:'.', decimal:',', affixesStay: false});
  • '.maskMoney()' only works with the specific library, as Sam reported in another reply.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.