用jquery实现的文本框只能输入数字简单插件
$.fn.numeral = function() {
$(this).css("ime-mode", "disabled");
this.bind("keypress",function(e) {
var e = e||event;
var currKey = e.keyCode||e.which||e.charCode;
if (currKey == 46) {
if (this.value.indexOf(".") != -1) {
return false;
}
}else {
return currKey >= 46 && currKey <= 57 || currKey == 8;
}
});
this.bind("blur", function() {
if (this.value.lastIndexOf(".") == (this.value.length - 1)) {
this.value = this.value.substr(0, this.value.length - 1);
} else if (isNaN(this.value)) {
this.value = "0";
}
});
this.bind("paste", function() {
var s = clipboardData.getData('text');
if (!/\D/.test(s));
value = s.replace(/^0*/, '');
return false;
});
this.bind("dragenter", function() {
return false;
});
this.bind("keyup", function() {
if (/(^0+)/.test(this.value)) {
this.value = this.value.replace(/^0*/, '');
}
});
};