js转换数字类型丢失精确度

出现过程:

<input type="button" value="修改" class="btn control" style="margin: 0 0 0 10px" onclick="operaterLabel(${label.labelId},1)">

function operaterLabel(labelId,type) {

window.open ('operaterLabel.do?labelId='+labelId +"&type=" + type, 'newwindow', 'height=700, width=780, top=100, left=800, toolbar=no, menubar=no, scrollbars=no, resizable=no,location=n o, status=no')

}

operaterLabel方法触发的时候,如果入参labelId是比较大的整数,比如820959798718763008,js会强制转换为820959798718763000,丢失精度了。解决方法是,入参的时候,以字符串的形式即可,如:

onclick="operaterLabel('${label.labelId}',1)"

猜你喜欢

转载自breezylee.iteye.com/blog/2283084
今日推荐