如何在javascript中为id获取不同的值?

如何在javascript中为id获取不同的值?,javascript,php,Javascript,Php,我试图从id kode中为脚本获取不同的值。我的脚本只获取第一个值 <table id="myTable" style="margin-left: 50px;"> <tr class="header"> <th style="width:30%;"></th> <th style="width:30%;"></th>

我试图从id kode中为脚本获取不同的值。我的脚本只获取第一个值

<table id="myTable" style="margin-left: 50px;">
              <tr class="header">
                <th style="width:30%;"></th>
                <th style="width:30%;"></th>
                <th style="width:30%;"></th>
              </tr>
              <?php 
                foreach ($barang as $br) 
                { ?>
                  <tr>
                    <td><?php echo $br->nama_barang ?></td>
                    <td><input type="text" id="kode<?php echo $br->kode_barang ?>" value="<?php echo $br->kode_barang ?>" readonly="true"></td>
                    <td><button style="color: blue;" onclick="getkode<?php echo $br->kode_barang ?>()">get</button></td>
                  </tr>
                <?php }
              ?>
            </table>
 <td><button style="color: blue;" onclick="getkode('<?php echo $br->kode_barang ?>')">get</button></td>

好的,这就是我要做的

 <td><button style="color: blue;" onclick="getkode('<?php echo $br->kode_barang ?>')">get</button></td>
改变这些:

 <td><button style="color: blue;" onclick="getkode<?php echo $br->kode_barang ?>()">get</button></td>
 <td><button style="color: blue;" onclick="getkode('<?php echo $br->kode_barang ?>')">get</button></td>
顺便说一句,我不久前写了这个jQuery剪贴板插件,如果你愿意,欢迎你使用它

 <td><button style="color: blue;" onclick="getkode('<?php echo $br->kode_barang ?>')">get</button></td>

 <td><button style="color: blue;" onclick="getkode('<?php echo $br->kode_barang ?>')">get</button></td>
如果我没记错我自己的代码,你会做类似的事情

 <td><button style="color: blue;" onclick="getkode('<?php echo $br->kode_barang ?>')">get</button></td>
$('body').jqClipboard('copy', html);

它使用动态创建的文本区域来复制内容。因此,它可以将任何HTML复制到剪贴板,即使只是字符串。

jquery
中,我会这样做
$(输入[id^=“kode”]”)
或以选择器开头。您的id不是kode它的
id=“kode”
任何东西。您长期打算做什么?现在看来,要想得到你已经拥有的东西,这是一种非常复杂的方式($br->kode_barang)。您只需将其传递到
onclick=“getkode()”
@jeff-看起来他们正在将其复制到剪贴板。点击按钮。
 <td><button style="color: blue;" onclick="getkode('<?php echo $br->kode_barang ?>')">get</button></td>