use*_*021 3 html javascript jquery javascript-events
我想用jquery中的k,lacs,crores将数字格式化为它们旁边的数字:
1000至1K
1500至1.5K
100000到1Lac
150000至1.5Lac
1000000到10Lac
10000000到1cr等等!
<!DOCTYPE html>
<html>
<head>
<title>Number Differentiation</title>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function(e){
$('#numbr').bind('keypress', function (e) {
return (e.which != 8 && e.which != 0 && (e.which < 48 || e.which > 57) && e.which != 46) ? false : true;
});
$("#submitBut").click(function(e){
alert(numDifferentiation( $("#numbr").val()))
})
function numDifferentiation($val){
return $val;
}
})
</script>
</head>
<body>
<input id="numbr" type="text"/>
<button id="submitBut">Click</button>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
tec*_*bar 10
这应该这样做:
function numDifferentiation(val) {
if(val >= 10000000) val = (val/10000000).toFixed(2) + ' Cr';
else if(val >= 100000) val = (val/100000).toFixed(2) + ' Lac';
else if(val >= 1000) val = (val/1000).toFixed(2) + ' K';
return val;
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3366 次 |
| 最近记录: |