Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/82.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Jquery 如何限制用户在输入值中仅写入4位数字?_Jquery_Html_Input - Fatal编程技术网

Jquery 如何限制用户在输入值中仅写入4位数字?

Jquery 如何限制用户在输入值中仅写入4位数字?,jquery,html,input,Jquery,Html,Input,我想强制用户写入一个输入值,在“.”之后最多有2个数字 例如:24.14或5.7或0.5或8,而不是4.321或5.133121。我该怎么做呢?您不能强制任何对象,但可以在用户输入后将其格式化为十进制 <input type="text" id="input_id"> //format decimal value while typing (function($) { $.fn.currencyFormat = function() { this.eac

我想强制用户写入一个输入值,在“.”之后最多有2个数字
例如:24.14或5.7或0.5或8,而不是4.321或5.133121。我该怎么做呢?

您不能强制任何对象,但可以在用户输入后将其格式化为十进制

 <input type="text" id="input_id">

 //format decimal value while typing
(function($) {
    $.fn.currencyFormat = function() {
        this.each( function( i ) {
            $(this).change( function( e ){
                if( isNaN( parseFloat( this.value ) ) ) return;
                this.value = parseFloat(this.value).toFixed(2);
            });
        });
        return this; //for chaining
    }
})( jQuery );


$( function() {
    $("#input_id").currencyFormat();       
});

//键入时格式化十进制值
(函数($){
$.fn.currencyFormat=函数(){
这是每个功能(i){
$(此).更改(功能(e){
if(isNaN(parseFloat(this.value)))返回;
this.value=parseFloat(this.value).toFixed(2);
});
});
返回此;//用于链接
}
})(jQuery);
$(函数(){
$(“#输入_id”).currencyFormat();
});

您不能强制任何对象,但可以在用户输入后将其格式化为十进制

 <input type="text" id="input_id">

 //format decimal value while typing
(function($) {
    $.fn.currencyFormat = function() {
        this.each( function( i ) {
            $(this).change( function( e ){
                if( isNaN( parseFloat( this.value ) ) ) return;
                this.value = parseFloat(this.value).toFixed(2);
            });
        });
        return this; //for chaining
    }
})( jQuery );


$( function() {
    $("#input_id").currencyFormat();       
});

//键入时格式化十进制值
(函数($){
$.fn.currencyFormat=函数(){
这是每个功能(i){
$(此).更改(功能(e){
if(isNaN(parseFloat(this.value)))返回;
this.value=parseFloat(this.value).toFixed(2);
});
});
返回此;//用于链接
}
})(jQuery);
$(函数(){
$(“#输入_id”).currencyFormat();
});

您不能强制任何对象,但可以在用户输入后将其格式化为十进制

 <input type="text" id="input_id">

 //format decimal value while typing
(function($) {
    $.fn.currencyFormat = function() {
        this.each( function( i ) {
            $(this).change( function( e ){
                if( isNaN( parseFloat( this.value ) ) ) return;
                this.value = parseFloat(this.value).toFixed(2);
            });
        });
        return this; //for chaining
    }
})( jQuery );


$( function() {
    $("#input_id").currencyFormat();       
});

//键入时格式化十进制值
(函数($){
$.fn.currencyFormat=函数(){
这是每个功能(i){
$(此).更改(功能(e){
if(isNaN(parseFloat(this.value)))返回;
this.value=parseFloat(this.value).toFixed(2);
});
});
返回此;//用于链接
}
})(jQuery);
$(函数(){
$(“#输入_id”).currencyFormat();
});

您不能强制任何对象,但可以在用户输入后将其格式化为十进制

 <input type="text" id="input_id">

 //format decimal value while typing
(function($) {
    $.fn.currencyFormat = function() {
        this.each( function( i ) {
            $(this).change( function( e ){
                if( isNaN( parseFloat( this.value ) ) ) return;
                this.value = parseFloat(this.value).toFixed(2);
            });
        });
        return this; //for chaining
    }
})( jQuery );


$( function() {
    $("#input_id").currencyFormat();       
});

//键入时格式化十进制值
(函数($){
$.fn.currencyFormat=函数(){
这是每个功能(i){
$(此).更改(功能(e){
if(isNaN(parseFloat(this.value)))返回;
this.value=parseFloat(this.value).toFixed(2);
});
});
返回此;//用于链接
}
})(jQuery);
$(函数(){
$(“#输入_id”).currencyFormat();
});

您可以使用将数字转换为字符串的方法,保持指定的小数位数

样本

var myNum = document.getElementById("textboxID").value;
myNum = parseFloat(myNum).toFixed(2); //I fixed my precision to 2 digits after "."
您可以使用将数字转换为字符串的方法,保持指定的小数位数

样本

var myNum = document.getElementById("textboxID").value;
myNum = parseFloat(myNum).toFixed(2); //I fixed my precision to 2 digits after "."
您可以使用将数字转换为字符串的方法,保持指定的小数位数

样本

var myNum = document.getElementById("textboxID").value;
myNum = parseFloat(myNum).toFixed(2); //I fixed my precision to 2 digits after "."
您可以使用将数字转换为字符串的方法,保持指定的小数位数

样本

var myNum = document.getElementById("textboxID").value;
myNum = parseFloat(myNum).toFixed(2); //I fixed my precision to 2 digits after "."
这可能适用于您: 以下是文本输入:

 <input type="text" id="tb1" >
这可能适用于您: 以下是文本输入:

 <input type="text" id="tb1" >
这可能适用于您: 以下是文本输入:

 <input type="text" id="tb1" >
这可能适用于您: 以下是文本输入:

 <input type="text" id="tb1" >

我找到了解决办法。您可以从Jquery使用这个api:

我找到了一个解决方案。您可以从Jquery使用这个api:

我找到了一个解决方案。您可以从Jquery使用这个api:

我找到了一个解决方案。您可以从Jquery使用此api:

可能重复最好在主持人关闭之前修改您的问题。可能重复最好在主持人关闭之前修改您的问题。可能重复最好在主持人关闭之前修改您的问题。可能重复最好在主持人关闭之前修改您的问题。可能重复最好修改您的问题在版主关闭它之前。