HTML页面:
<div class=" row t1" style="text-align:center;"> <div class="form-group col-xs-2 col-md-offset-1"> <div class="panel panel-danger" style="background-color:whitesmoke"> <div class="panel-heading" style="background-color:orangered;color:white"> <h3 class="panel-title">需扫描数</h3> </div> <div class="panel-body tt" style="color:orangered;font-size:15px;font-weight:bold;" data-key="Scaned"> 0 </div> </div> </div> <div class="form-group col-xs-2 col-md-offset-2"> <div class="panel panel-success" style="background-color:whitesmoke"> <div class="panel-heading" style="background-color:green;color:white"> <h3 class="panel-title">已扫描数</h3> </div> <div class="panel-body" style="color:green;font-size:15px;font-weight:bold;" id="tt" data-key="BeScaned"> 0 </div> </div> </div> <div class="form-group col-xs-2 col-md-offset-2"> <div class="panel panel-default" style="background-color:whitesmoke"> <div class="panel-heading" style="background-color:grey;color:white"> <h3 class="panel-title">待扫描数</h3> </div> <div class="panel-body" style="font-size:15px;font-weight:bold;" data-key="WaitScaned"> 0 </div> </div> </div> </div>
JavaScript:
$.get(_reqUrl.getData, { MemberName: $.trim(MemberName) }, function (result) { var model = result.Custom; var t1 = model.t1[0]; //t1 = {Scaned: 2, BeScaned: 0, WaitScaned: 2}; $.each($('.t1').find('div[data-key]'), function (i, m) { $(m).html(t1[$(m).attr('data-key')]); }); });
效果图: