有谁可以告诉我为什么我的“Id”总是在最后添加零?以及如何解决这个问题?
<script id="myTemplate" type="text/x-jquery-tmpl">
<tr id='${Id}'>${Id}</tr>
</script>
<div id="tblMyTable"></div>
$(document).ready(function(){
var test = [
{ Id: 43000796568231936 , ReleaseYear: "1998" },
{ Id: 43000796568231937 , ReleaseYear: "1999" },
{ Id: 43000796568231938 , ReleaseYear: "1976" }
];
$("#myTemplate").tmpl(test).appendTo("#tblMyTable");
});
答案 0 :(得分:1)
看起来像JS WTF ......
alert(parseInt(43000796568231936));
它正在将您的号码更改为43000796568231940。
这种情况发生在Google Chrome,Firefox和IE中。
您可以通过将整数更改为字符串来解决此问题:http://jsfiddle.net/55u9M/16/
从以下位置更改您的JSON:
var test = [
{ Id: 43000796568231936, ReleaseYear: "1998" },
{ Id: 43000796568231937, ReleaseYear: "1999" },
{ Id: 43000796568231938, ReleaseYear: "1976" }
];
要
var test = [
{ Id: '43000796568231936', ReleaseYear: "1998" },
{ Id: '43000796568231937', ReleaseYear: "1999" },
{ Id: '43000796568231938', ReleaseYear: "1976" }
];