更新时间:2023-02-19 23:16:05
在@elclanrs和@mgibsonbr的帮助下,我来到了这里:
With the help of @elclanrs and @mgibsonbr, I came to this:
$j = jQuery.noConflict();
$j(function() {
$j("input").keypress(function(e) {
var val = $j(this).val();
var regex = /^(\+|-)?(\d*\.?\d*)$/;
if (regex.test(val + String.fromCharCode(e.charCode))) {
return true;
}
return false;
});
});
可在此处进行测试: http://jsfiddle.net/9U2Mw/5/