jQuery doesn’t want to run on mobile

Asked

Viewed 37 times

0

I’m using a function so that when one clicks on the inputs the value is replaced by monetary value, but on mobile only works if one clicks on "ok" or "go", and I wanted it to run as soon as one clicks on the input.

Code used:

$("#valorsaquemobi").click(function(){
var mask = {
  money: function() {
    var el = this
    ,exec = function(v) {
    v = v.replace(/\D/g,"");
    v = new String(Number(v));
    var len = v.length;
    if (1== len)
    v = v.replace(/(\d)/,"0.0$1");
    else if (2 == len)
    v = v.replace(/(\d)/,"0.$1");
    else if (len > 2) {
    v = v.replace(/(\d{2})$/,'.$1');
    }
    return v;
    };

    setTimeout(function(){
    el.value = exec(el.value);
    },1);
  }

 }

 $(function(){
  $('input#valorsaquemobi').bind('keypress',mask.money)
 });
  });

input:

 <input type="text" class="form-control input-cadastrar rr" id="valorsaquemobi" onclick="mobisaque()">
  • 1

    Trade onclick for onfocus.

  • worked, but only if there is one more input, if n it gave, I was wanting like onkeypress

No answers

Browser other questions tagged

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