$.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
解决方案 »
- 网关的短信接口 全语言支持 开发工具包代码说明留着备用吧。。
- 为什么我的js在IE6有效果,可是在ff等不是IE6的就没有效
- 求助$.post()返回值与外层函数返回值的问题?
- struts2控件问题(Radio)
- javascript中能否实现车的运行?
- setTimeOut 在类内部的方法内进行递归,有问题
- 用javascript修改了某一个cookie的值后,怎么修改有效期
- jquery中$(document).on的一些疑惑
- 怎样实现在使用confirm()函数同时打开另外一个窗口 ?
- 谢谢 meizz(梅花雨),evonne_feng(evonne)等大虾帮助!!!
- radio
- js刷新页面
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*/, '');
}
});