<p>履歴</p>
<table border width="100%" height="20px">
<tr>
<th>月</th>
<th>火</th>
<th>水</th>
<th>木</th>
<th>金</th>
<th>土</th>
<th>日</th>
</tr>
<tr>
<td>1-1</td>
<td>1-2</td>
<td>1-3</td>
<td>1-4</td>
<td>1-5</td>
<td>1-6</td>
<td>1-7</td>
</tr>
<tr>
<td>2-1</td>
<td>2-2</td>
<td>2-3</td>
<td>2-4</td>
<td>2-5</td>
<td>2-6</td>
<td>2-7</td>
</tr>
<tr>
<td>3-1</td>
<td>3-2</td>
<td>3-3</td>
<td>3-4</td>
<td>3-5</td>
<td>3-6</td>
<td>3-7</td>
</tr>
<tr>
<td>4-1</td>
<td>4-2</td>
<td>4-3</td>
<td>4-4</td>
<td>4-5</td>
<td>4-6</td>
<td>4-7</td>
</tr>
<tr>
<td>5-1</td>
<td>5-2</td>
<td>5-3</td>
<td>5-4</td>
<td>5-5</td>
<td>5-6</td>
<td>5-7</td>
</tr>
</table>
<script>
var data = [];
var tr = $("table tr");//テーブルの全行を取得
for( var i=0,l=tr.length;i<l;i++ ){
var cells = tr.eq(i).children();//1行目から順番に列を取得(th、td)
for( var j=0,m=cells.length;j<m;j++ ){ //m=cells.length;j<m;j++
if( typeof data[i] == "undefined" )
data[i] = [];
data[i][j] = cells.eq(j).text();//i行目j列の文字列を取得
}
}
console.log(data);
console.log(tr.length);
console.log(cells.length);
</script>
コメント