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

Javascript 在php中,如何为while循环中创建的每个输入文本框生成动态id,javascript,php,jquery,ajax,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']?>" onchan

如何获取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>

函数loadXMLDoc(a,i)
{var d=document.getElementById(“hello”+i.value;}
使用
uniqid()
函数
$str=uniqid(“uid”)
它将生成类似于ti-uid1hq7266的东西

并在输入中打印,不要使用foreach作为下面的方式。

foreach($sql1 as $value){

// don't generate html here

}
因为它可能会阻止html

使用下面的方法

<?php

foreach($sql1 as $value):

?>

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

<?php endforeach() ?>


我不明白您的问题您想获取多个复选框的val吗?或者在php中生成一个dinaimiq id?我想为TextBox生成动态id这是关于uniqid函数loadXMLDoc(a){var d=document.getElementById(hello.value;}的所有文档如果您想从当前文本中获取值,那么如何在此处获取该id,然后使用onchange='loadXMLDoc(this.value)它将返回更改输入文本的值have look@my edited answer…你也将知道如何获得准确的字段值。。