html输入框只允许输入数字及小数点

来源:互联网 发布:智能算法 编辑:程序博客网 时间:2024/06/09 13:51

$("#num").css({"ime-mode" : "disabled"}).keypress(function(e) {if (e.which == 45) { //-return true;}if (e.which == 46) { //.var cnt = 0;for (var m = 0; m < $(this).val().length; m++) {if ($(this).val().charAt(m) == ".")cnt++;if (cnt > 0)return false;}return true;} else if ((e.which >= 48 && e.which <= 57 && e.ctrlKey == false && e.shiftKey == false) || e.which == 0 || e.which == 8) {return true;} else if (e.ctrlKey == true && (e.which == 99 || e.which == 118)) {return true;} else {return false;}}).paste(function() {if (window.clipboardData) {var s = clipboardData.getData('text');if (!/\D/.test(s)) {return true;} else {return false;}} else {return false;}}).dragenter(function() {return false;}).blur(function() {if (self.options.fix) {self._fixValue(target);}});

只允许输入数字,小数点,减号


原创粉丝点击