jquery实现控制input框只能输入数字,保留一位小数
$(document).ready(function() {
$('#project_time').on('input', function() {
this.value = this.value.replace(/[^0-9.]/g, '');
if (this.value.indexOf('.') !== -1) {
var decimalIndex = this.value.indexOf('.');
if (this.value.slice(decimalIndex + 1).length > 1) {
this.value = this.value.slice(0, decimalIndex + 2);
}
}
});
});
本作品采用《CC 协议》,转载必须注明作者和本文链接