Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/89.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 向表的活动td类显示一些值_Javascript_Jquery_Html - Fatal编程技术网

Javascript 向表的活动td类显示一些值

Javascript 向表的活动td类显示一些值,javascript,jquery,html,Javascript,Jquery,Html,我有一个动态表,当我点击一个tr时,它的类变为active。在表的td中,我有一个输入字段。实际上,我想在表的活动td中显示一些内容 $('#product').val(item['name']); 通过这个,我可以将我的值显示给id为product的div。但如何向表中的活动td显示此信息 <table id = "mytable"> <tr> <td class = "active"><input type ="text" name

我有一个动态表,当我点击一个tr时,它的类变为active。在表的td中,我有一个输入字段。实际上,我想在表的活动td中显示一些内容

   $('#product').val(item['name']);
通过这个,我可以将我的值显示给id为product的div。但如何向表中的活动td显示此信息

<table id = "mytable">
 <tr>
    <td class = "active"><input type ="text" name="product[]" id="product"> </td>
    <td class = "active">some data</td>
 </tr>
 <tr>
    <td class=""><input type ="text" name="product[]" id="product"></td>
    <td class = "">some data</td>
</tr>
</table>

一些数据
一些数据
这是我的桌子。正如我所说,这张桌子是动态的。这就是id重复的原因。如果它是一个静态表,我可以在输入字段product$(“#product').val(item['name'])中显示我的值。但当它变为动态时,我希望将活动tds值打印到输入字段。

但是请帮助我,我被困在这里。

那么,当td被聚焦时,你想在其中显示一些价值吗? 你可以这样做

$( "#td" ).focus(function() {
   $('#product').val(item['name']);
});

请根据您在
td
中所说的内容,提供相关的html示例,并提供更多有关该操作的详细信息。您有一个
input
字段。定义要执行的单词
stuff
?您只需创建一个计数器,然后每次添加一行,使
id='product'+计数器