如何使用jQuery和JavaScript选择一行中的特定列? [英] How can I select a specific column in a row using jQuery and JavaScript?

查看:47
本文介绍了如何使用jQuery和JavaScript选择一行中的特定列?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是jQuery和JavaScript的新手。
我有一个小问题。
假设我有一个HTML表格,如下所示

I am very new to jQuery and JavaScript. I have a small question. Let's say i have a HTML table like the following

<Table id="mytable">
 <tr id="element">
  <td>value</td>
  <td>text</td>
</tr>
</Table>

在上面的例子中我知道行id,我想改变第二列的值具有该特定ID的行。

In the above example i know the row id and i want to change the value of the second column of the row with that particular id.

我需要如下结果:

 <Table id="mytable">
 <tr id="element">
  <td>value</td>
  <td>ChangedText</td>
</tr>
</Table>

所以我的问题是:如何选择2 nd 列具有给定id的第一行以更改值?

So my question is: how can I select the 2nd column of the first row with a given id in order to change the value?

推荐答案

$("#element td:nth-child(2)").text('ChangedText');

这是一个例子

这篇关于如何使用jQuery和JavaScript选择一行中的特定列?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆