js获取当前行元素

创建表格

<table >
<tr>
                <th>分类</th>
                <th>名称</th>
                <th>单价(元)</th>
                <th>单位</th>
</tr>
<tr>
              <td>饮料</td>
              <td>雪碧</td>
             <td>3</td>
             <td>瓶</td>
</tr>
</table>

获取单元格的值

function get_data(){
$("button").click(function(){
var td0=$(this).parents("tr").find("td").eq(0).text();
//td0为按钮所在行第一列的值,=>饮料
  }
}

猜你喜欢

转载自1175644344.iteye.com/blog/2314642