javascript - 在 php 中,我如何为 while 循环中创建的每个输入文本框生成动态 id

标签 javascript php jquery ajax

如何获取在 while 循环中生成的选定文本框 ID,以便像在 phpmyadmin 中一样更新字段

 <?php
    while($fet=mysql_fetch_assoc($sql1))
    {
        ?>
        <tr>
        <td><input type=text id='hello' name='hello' data-id="<?php echo  $fet['username']?>"     onchange='loadXMLDoc(this);' value=<?php echo $fet['username']?>>
       <td><input type=text id='uid' name='uid' onchange='loadXMLDoc(this).' value=<?php echo  $fet['id']?>>
       </tr>
       <?php 
        }
  ?>

最佳答案

只需附加 i 并递增它直到你的 while 循环继续..

<?php
    $i=1;
    while($fet=mysql_fetch_assoc($sql1))
    {
       echo '
        <tr>
        <td>
          <input type="text" id="hello'.$i.'" name="hello'.$i.'" data-id="'.$fet['username'].'" onchange="loadXMLDoc(this.value,'.$i.')" value='.$fet['username'].' >
</td>           
       </tr>';
       here write ur code for other fields

         $i++;
    }
 ?>

<script> 
function loadXMLDoc(a,i) 
{ var d= document.getElementById("hello"+i).value; } 
</script>

关于javascript - 在 php 中,我如何为 while 循环中创建的每个输入文本框生成动态 id,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22265184/

相关文章:

jQuery 模板已被弃用?

javascript - 如何用jQuery获取li中隐藏的值?

javascript - 比较 url 字符串和菜单字符串,然后使用 jquery 添加类

php - 如何将 val 传递给 val 而不会出现这些错误 : Notice: Undefined index

javascript - 获取今天的科普特日期

Javascript 英国邮政编码正则表达式

javascript - 为什么 onBeforeFirstShow 有效?

PHP Regex 在连字符 (-) 前后获取值

php - 推送通知安卓 GCM

php - 使用 MySQL 和 PHP 查找重复内容