您的位置:首页 > Web前端 > HTML

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

2017-09-04 13:57 225 查看
$("#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);
}
});

只允许输入数字,小数点,减号
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: