2013/12/26 13:59:04
分类:WEB技术
jquery 限制文本框只能输入数字
Java代码 
- jquery 限制文本框只能输入数字
-
- 转自:http:
-
- $("input[name=\'fangwenyudinhuishu\']").keyup(function(){
- var tmptxt=$(this).val();
- $(this).val(tmptxt.replace(/\\D|^0/g,\'\'));
- }).bind("paste",function(){
- var tmptxt=$(this).val();
- $(this).val(tmptxt.replace(/\\D|^0/g,\'\'));
- }).css("ime-mode", "disabled");
-
-
-
- 上面是keyup事件处理,下面处理了CTR+V事件,最后就是CSS设置输入法不可用
----------------------------------------------------------------------------------------------------------------------------------------------------------------
- 用jquery限制文本框只能输入数字:
-
- 程序:
-
- $(function(){
-
-
- $.fn.numeral = function() {
- $(this).css("ime-mode", "disabled");
- this.bind("keypress",function(e) {
- var code = (e.keyCode ? e.keyCode : e.which);
- 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*/, \'\');
- }
- });
- };
-
- $("#score").numeral();
-
- });
标签:
本文由胡金金个人网站整理发布,转载请注明地址:http://www.hujinjin.com/info/451.html
凡标明来源于胡金金个人网站的文章,皆为本站整理发布,若转载此文必须附原文链接,对部分平台更改其文内容当自己原创者,胡金金个人网站将保留其追究权利!
个人资讯推荐