[{"dir":"down","sym":"oo","b":"1.35553","a":"1.35556"},
{"dir":"down","sym":"pp","b":"1.64442","a":"1.64451"},
{"dir":"down","sym":"qq","b":"104.603","a":"104.609"},
{"dir":"up","sym":"rr","b":"0.88186","a":"0.88191"},
{"dir":"up","sym":"ss","b":"1.09667","a":"1.09672"}]
从上面的json我需要为b&添加 使用jquery的最后一位数字,我的jquery是
<script type="text/javascript">
jQuery(window).load(function(){
setInterval(function() {
$.ajax({
cache: false,
url: 'get.php',
dataType: 'json',
success: function(json){
var dd="";
for(var i=0;i<json.length;i++){
if(json[i].dir == 'up'){
var ii= '<img src="img/up.gif" />';
} else {
var ii= '<img src="img/down.gif" />';
}
dd += ii + '-' + json[i].sym+ '-' + json[i].b+ '-' + json[i].a+'--';
}
$('#divToRefresh').html(dd);
}
});
}, 1000);
});
</script>
我需要这个例子:
json[0].b="1.35553"; json[0].a="1.35556";
我如何从json代码通过jquery得到上面的例子,任何想法..
答案 0 :(得分:1)
试试这个:
var a = 1.35556.toString();
var start = a.substr(0, a.length-1);
var end = a.substr(-1);
console.log(start + end.sup()); // 1.3555<sup>6</sup>