2016-08-21 58 views
0

我使用的是jquery mobile 1.45。将输入用作数字时,我想将小数位数限制为两位数。jquery mobile两位小数

我的意见如下:

<input type="number" style="text-align: right" step="0.01" min="0"> 

回答

0

这算什么,你

<html> 
 
<head></head> 
 
<title></title> 
 

 
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script> 
 

 

 
</style> 
 

 
<body> 
 

 
Enter the number : <input type="number" style="text-align: right" step="0.01" min="0" id="mynumber"> 
 

 

 
</body> 
 

 
<script type="text/javascript"> 
 

 
$("#mynumber").on('keyup',function(){ 
 
    var thevalue = parseFloat($(this).val()); 
 
    var fixedNum = thevalue.toFixed(2); 
 
    $(this).val(fixedNum); 
 
    
 
    if (thevalue/fixedNum < 1) 
 
    { 
 
     alert("please enter only 2 decimal places."); 
 
    } 
 

 
}); 
 

 

 
</script> 
 

 
</html>

希望这将有助于你。

+0

此代码不能正常工作 –

+0

请尝试使用现场示例 –

+0

我做过。但它仍然不起作用。你甚至不能写数字 –