cssAudio - Activefile-genericCSS - ActiveGeneric - ActiveHTML - ActiveImage - ActiveJS - ActiveSVG - ActiveText - Activefile-genericVideo - ActiveLovehtmlicon-new-collectionicon-personicon-teamlog-outoctocatpop-outspinnerstartv

Pen Settings

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

Quick-add: + add another resource

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

Quick-add: + add another resource

Code Indentation

     

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

            
              <table class="table">
  <tr>
    <th>ID</th>
    <th>Name</th> 
    <th>Age</th>
  </tr>
  <tr>
    <td>id-0001</td>
    <td><span data-key="name" data-id="id-0001">Leon</span></td>
    <td><span data-key="age" data-id="id-0001">18</span></td>
  </tr>
  <tr>
    <td>id-0002</td>
    <td><span data-key="name" data-id="id-0002">Wendy</span></td>
    <td><span data-key="age" data-id="id-0002">20</span></td>
  </tr>
</table>
            
          
!
            
              table, th, td {
    border: 1px solid black;
    border-collapse: collapse;
}
th, td {
    padding: 5px;
    text-align: left;    
}

            
          
!
            
              $(function(){
  var Tbdata = {}; 
  var tr_length = $('.table tr').length; //tr 長度
  for(var i=0; i < tr_length; i++){
    var td_length = $('.table tr')[i].childElementCount; //當下td長度
    if(i>=1){ //從第二列開始取值
    Tbdata[i] = {};
      for(var v=0; v < td_length; v++){
        if(v>=1){ //從第二欄開始取值
            Tbdata[i][v] = {};
            Tbdata[i][v]['value'] = $('.table tr:eq('+i+') td:eq('+v+')').text();
            Tbdata[i][v]['key'] = $('.table tr:eq('+i+') td:eq('+v+') span').data('key');
            Tbdata[i][v]['id'] = $('.table tr:eq('+i+') td:eq('+v+') span').data('id');
        }
      }
     }
  }
  console.log(Tbdata);
});

//output
// {
//   "0":{
//     "1":{
//       "value":"Leon",
//       "key":"name",
//       "id":"id-0001"
//     },
//     "2":{
//       "value":"18",
//       "key":"age"
//       "id":"id-0001"
//     }
//   },
//   "1":{
//     "1":{
//       "value":"Wendy",
//       "key":"name"
//       "id":"id-0002"
//     },
//     "2":{
//       "value":"20",
//       "key":"age"
//       "id":"id-0002"
//     }
//   }  
// }
            
          
!
999px
Loading ..................

Console