简体   繁体   English

如何从动态列表中获取输入值

[英]How to get a input value from dynamic list

I don't know how to get the value, with js always show me the first input value!不知道怎么取值,用js总是显示第一个输入值! Thanks in advance!!!提前致谢!!!

<html>
<head>
</head>
<body>
<?php 
while($i < $forid){
?>
<div id="mydiv">
    <input type="text" id="myid" name="myid" value="<?php echo $arrayid[$i]; ?>">
    <input type="text" id="myname" name="myname" value="<?php echo $arrayname[$i];?>">
    <input type="text" id="myjob"name="myjob" value="<?php echo $arrayjob[$i]; ?>">
    <input type="submit" value="get values" id="getvaluesbutton">
</div>  
<?php
$i++;
}
?>
</body>
</html>

Get array access to elements by class/name in your js script by changing html:通过更改 html,在 js 脚本中按类/名称获取对元素的数组访问:

<?php 
while($i < $forid){
?>
<div id="mydiv">
    <input type="text" name="myid[]" class="myid" value="<?php echo $arrayid[$i]; ?>">
    <input type="text" name="myname[]" class="myname" value="<?php echo $arrayname[$i];?>">
    <input type="text" name="myjob[]" class="myjob" value="<?php echo $arrayjob[$i]; ?>">
    <input type="submit" value="get values" id="getvaluesbutton">
</div>  
<?php
$i++;
}
?>

for javascript hints read this question对于 javascript 提示,请阅读此问题

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM