如何在jQuery中获取元素的文本值?
我有一个动态生成的HTML表,并且动态地为每一行生成了字段名.
I have an HTML table generated dynamically with field names generated for each row dynamically as well.
这是表格中的结构.我有一个<td>
标记,在其中有一个<span>
标记.我想获取每个标签的值.我已经尝试过这种方式:
Here is the structure I have within the table. I have a <td>
tag and within it I have a <span>
tag. I want to get the value for each tag. I have tried this this way:
$("#txtname").attr('value',$("#table1").find('td > #selname_'+i).text());
在上面的代码中,我使用<span>
标记(selname)中的值设置$("#txtname")
(文本框值). i
是递增值.
In the above code I am setting the $("#txtname")
(textbox value) with the value from the <span>
tag (selname). Here i
is an incrementing value.
我想获取文本,但不获取<span>
值,因此我无法为其赋值.
I want to get the text, but do not get the <span>
value, and I am not able to assign to it.
无需使选择器变得如此复杂:
No need to make your selectors so complicated:
$("#txtname").val($("#selname_"+i).text());