javascript jquery中的自动十进制数输入

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了javascript jquery中的自动十进制数输入相关的知识,希望对你有一定的参考价值。

	$('input.number').keyup(function(event) {

  // skip for arrow keys
  if(event.which >= 37 && event.which <= 40){
   event.preventDefault();
  }

  $(this).val(function(index, value) {
      value = value.replace(/,/g,'');
      return numberWithCommas(value);
  });
});

function numberWithCommas(x) {
    var parts = x.toString().split(".");
    parts[0] = parts[0].replace(/\B(?=(\d{3})+(?!\d))/g, ",");
    return parts.join(".");
}


 //persian number
(function(a){a.extend({persianNumbers:function(b){var g={0:"۰",1:"۱",2:"۲",3:"۳",4:"۴",5:"۵",6:"۶",7:"۷",8:"۸",9:"۹"};var d=(b+"").split("");var f=d.length;var c;for(var e=0;e<=f;e++){c=d[e];if(g[c]){d[e]=g[c]}}return d.join("")}})})(jQuery);

jQuery.persianNumbers(numberWithCommas(all)));



<input type="text" class="number" name="price" style="    text-align:left; direction:ltr; " value="<?php echo $t_price; ?>" required><br>
  
'price'  => str_replace(',','',$_POST['price']),
	
	
	
/* Example sub and sum button to input*/
<input class="form-control" name="price" type="text" placeholder="" value="100.000 تومان">
<input type="hidden" name="price_to_search" value="100000">
<button class="button left" type="button" data-enevtsum="sum">+</button>
<button class="button" type="button" data-enevtsum="sub">-</button>

<script>
jQuery(document).ready(function(){

(function(a){a.extend({persianNumbers:function(b){var g={0:"۰",1:"۱",2:"۲",3:"۳",4:"۴",5:"۵",6:"۶",7:"۷",8:"۸",9:"۹"};var d=(b+"").split("");var f=d.length;var c;for(var e=0;e<=f;e++){c=d[e];if(g[c]){d[e]=g[c]}}return d.join("")}})})(jQuery);
jQuery(document).on('click', '[data-enevtsum]', function(){
var typesum = jQuery(this).data('enevtsum');
var thisvalue = jQuery("input[name=price]").val();
var repl = parseInt(jQuery("input[name=price_to_search]").val());

let mo = 100000;
if(typesum ==="sub") {
var newprice = parseInt(repl) - mo;
} else {
var newprice = parseInt(repl) + mo;
}

jQuery("input[name=price_to_search]").val(newprice);
var parts = newprice.toString().split(".");
parts[0] = parts[0].replace(/\B(?=(\d{3})+(?!\d))/g, ",");
var new_price =  jQuery.persianNumbers(parts.join(".")) + " تومان";

jQuery("input[name=price]").val(new_price);
});




});
</script>

以上是关于javascript jquery中的自动十进制数输入的主要内容,如果未能解决你的问题,请参考以下文章

jQuery动画十进制数递增/递减

非零和非十进制数的 JQuery 正则表达式验证

使用 jquery 和 regex 格式化正负十进制数

Javascript/Jquery 验证按键/keydown 上的十进制输入

jQuery 中的自动完成功能只是...停止工作?

javaScript面向对象编程指南笔记