我的脚本:
function trimDecimalPlace(){
var curVal = $(".ui-inputNum > input:first-child").val();
var parseVal = '';
if(curVal.indexOf(".") > curVal.indexOf(",")){
var tokens = curVal.split(".");
var decimalVal = parseFloat("0."+tokens[1])+"";
if(decimalVal != "0"){
parseVal = tokens[0]+"."+decimalVal.substring(2);
}else{
parseVal = tokens[0];
}
}else{
var tokens = curVal.split(",");
var decimalVal = parseFloat("0."+tokens[1])+"";
if(decimalVal != "0"){
parseVal = tokens[0]+","+decimalVal.substring(2);
}else{
parseVal = tokens[0];
}
}
$(".ui-inputNum > input:first-child").val(parseVal);
}
并在模糊中调用它:
<pe:inputNumber
value="#{myBean.myVal}"
minValue="0" maxValue="999999999999999.999999999"
emptyValue="1"
onblur="trimDecimalPlace();"
thousandSeparator="."
decimalSeparator=","
/>