如何在jQuery中的onfocusout事件上调用函数

时间:2019-03-06 05:50:19

标签: javascript jquery ruby-on-rails ruby turbolinks

当我尝试使用“ virtualkeyboard”类调用“ focusout” jquery时,jquery不调用addThousandSeparator的功能

function addThousandSeparators(nStr) {
  nStr += '';
  var x = nStr.split('.');
  var x1 = x[0];
  var x2 = x.length > 1 ? '.' + x[1] : '';
  var rgx = /(\d+)(\d{3})/;
  while (rgx.test(x1)) {
      x1 = x1.replace(rgx, '$1' + ' ' + '$2');
  }
  return x1 + x2;
}

$(document).on("focusout", ".virtualkeyboard", function(){
    addThousandSeperators(this);
  });
<%= f.text_field :customer_price_estimation, :class => "form-control virtualKeyboard w150"%>

0 个答案:

没有答案