(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});
入力に問題があり、 の値が文字列ではなく整数でなければならないという問題があります。
しかし、私はそれも同様に2倍検証するコードを変更する必要があります。
0.22を挿入すると問題ありませんが、0.222 を挿入すると数字が入力されません。
それは良いでしょうことを示します。しかし、スクリプトにはいくつかの問題があります –
値の.22が許されているが、すべきではない主な問題 –
あなたの助けをありがとう –