File tree Expand file tree Collapse file tree 2 files changed +33
-7
lines changed
Expand file tree Collapse file tree 2 files changed +33
-7
lines changed Original file line number Diff line number Diff line change 1717 </ tr >
1818 </ thead >
1919 < tbody >
20- < tr >
20+ <!--< tr>
2121 <td>1</td>
2222 <td>xxx</td>
2323 <td>25</td>
24- </ tr >
25- < tr >
26- < td > 2</ td >
27- < td > xxx</ td >
28- < td > 26</ td >
29- </ tr >
24+ </tr>-->
3025 </ tbody >
3126</ table >
3227
Original file line number Diff line number Diff line change 1+ var stuList = document . getElementById ( 'stuList' ) ,
2+ stuHead = stuList . tHead ,
3+ stuBody = stuList . tBodies [ 0 ] ,
4+ stuHeadList = stuHead . getElementsByTagName ( 'th' ) ,
5+ stuRows = stuBody . rows ;
6+
7+ //->AJAX获取数据然后做数据绑定
8+ ~ function ( ) {
9+ //->GET DATA
10+ var stuData = null ;
11+ var xhr = new XMLHttpRequest ;
12+ xhr . open ( 'GET' , 'json/data.json' , false ) ;
13+ xhr . onreadystatechange = function ( ) {
14+ if ( xhr . readyState === 4 && xhr . status === 200 ) {
15+ stuData = utils . toJSON ( xhr . responseText ) ;
16+ }
17+ } ;
18+ xhr . send ( null ) ;
19+
20+ //->BIND DATA
21+ var str = `` ;
22+ for ( var i = 0 ; i < stuData . length ; i ++ ) {
23+ var cur = stuData [ i ] ;
24+ str += `<tr>
25+ <td>${ cur . id } </td>
26+ <td>${ cur . name } </td>
27+ <td>${ cur . age } </td>
28+ </tr>` ;
29+ }
30+ stuBody . innerHTML = str ;
31+ } ( ) ;
You can’t perform that action at this time.
0 commit comments