我使用以下代碼來檢查是否在文本框中的值是數字:檢查的值長度,並且如果它是數字
(function ($) {
$.fn.numeric = function (options) {
return this.each(function() {
var $this = $(this);
$this.keypress(options, function (e) {
// allow backspace and delete
if (e.which == 8 || e.which == 0)
return true;
//if the letter is not digit
if (e.which < 48 || e.which > 57)
return false;
// check max range
var dest = e.which - 48;
var result = this.value + dest.toString();
if (result > e.data.max) {
return false;
}
});
});
};
})(jQuery);
當輸入文本框元件上使用,我聲明它如下
$(input).numeric({ max: 999});
問題是它正在處理輸入並檢查 值應該是整數而不是字符串。
但我需要改變它將驗證double的代碼。
因此,如果我將插入0.22這將是確定的,但如果我將插入.22 它不會填充數字。
請幫
它的更好。但腳本有幾個問題 – 2011-12-21 13:42:30
主要問題是值.22允許,但不應該 – 2011-12-21 13:43:44
謝謝你的幫助 – 2011-12-21 13:43:58