首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > Ajax >

jquery的赋值有关问题

2012-02-04 
jquery的赋值问题 - Web 开发 / Ajaxxml文件片段:。。。。tabletbodytrtd1 /tdth300 /th/trt

jquery的赋值问题 - Web 开发 / Ajax
xml文件片段:

。。。。
<table>
<tbody>
  <tr>
  <td> 1 </td>
  <th> 300 </th>
  </tr>

  <tr>
  <td> 2 </td>
  <th> 400 </th>
  </tr>
</tbody>
</table>
。。。。


我现在想读取其中<td>和<th>中的数据,分别存入x,y中去

  $('tr',tbody).each(function(){
  data.push({
  x:td中的数据
  y:th中的数据
  });

  });



其中 x:td中的数据
  y:th中的数据

应该怎么写?谢谢

[解决办法]

HTML code
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js"></script><script type="text/javascript">var data = [];$(function(){    $('tr').each(function(){        var x = $(this).find("td:first").html();        var y = $(this).find("th").html();        data.push({            x:x,            y:y        });        alert(x + " " + y)    })    alert(data.length)})</script><table><tbody>  <tr>  <td>1</td>  <th>300</th>  </tr>  <tr>  <td>2</td>  <th>400</th>  </tr></tbody></table> 

热点排行