$.fn.numeral = function () {
$(this).css("ime-mode", "disabled");
this.bind("keypress", function (e) {
var code = (e.keyCode ? e.keyCode : e.which); //兼容火狐 IE
if (!$.browser.msie && (e.keyCode == 0x8)) //火狐下不能使用退格键
{
return;
}
return code >= 48 && code <= 57;
});
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 = "";
}
});
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*/, '');
}
});
};
使用:
$("#id_a01").numeral(); id_a01 是文本框的 id
以上是代码 这个代码运行起来可以实现只能输入数字 , 问题是 第一个输入不了 0
希望大神能解决这个问题。jquery
$(this).css("ime-mode", "disabled");
this.bind("keypress", function (e) {
var code = (e.keyCode ? e.keyCode : e.which); //兼容火狐 IE
if (!$.browser.msie && (e.keyCode == 0x8)) //火狐下不能使用退格键
{
return;
}
return code >= 48 && code <= 57;
});
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 = "";
}
});
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*/, '');
}
});
};
使用:
$("#id_a01").numeral(); id_a01 是文本框的 id
以上是代码 这个代码运行起来可以实现只能输入数字 , 问题是 第一个输入不了 0
希望大神能解决这个问题。jquery
function AgreeSubmit(doc) {
if (doc && doc.type.toLowerCase() == "checkbox") {
var btn = document.getElementById(doc.id.replace('checkboxagree', 'btnsubmit'));
if (btn && btn.type.toLowerCase() == "button") {
if (doc.checked) { btn.className = "btn100"; }
else { btn.className = "btn100_2"; }
btn.disabled = !doc.checked;
}
}
}这里模仿的不错
http://www.hellbear.com/app/list.htmlhttp://www.hellbear.com/app/list.html
if (/(^0+)/.test(this.value)) {
this.value = this.value.replace(/^0*/, '');
}
});