[英]copy data from textbox to other textbox only affect first row
i need your help, please. 我需要你的帮助。 i have a project needing a textbox (outside table) copy its data (percentage value) to textbox (percentage) inside the table. 我有一个需要文本框(外部表)的项目,将其数据(百分比值)复制到表内部的文本框(百分比)。 The problem is the data copied only fill first row textbox table. 问题是复制的数据仅填充第一行文本框表。 i hope it copied to entire row table. 我希望它复制到整个行表。
<table class='form'>
<thead>
<tr>
<th>Percentage input</th>
<th>:</th>
<td><input type='text' id='percentage_input'
</thead><tbody>
<table>
<thead>
<tr>
<th width>No.</th>
<th width>Percentage</th>
<th width>Score</th>
</tr></thead><tbody>";
$i = 1;
$sql_data = $db->database_prepare("SELECT * FROM score")->execute()
while ($data_score = $db->database_fetch_array($sql_data)){
echo "<tr>
<td>$i</td>
<td><input type='text' id='percentage' value='0'></td>
<td>$data_score[score]></td>
</tr>";
}
$i++;
</table>
javascript JavaScript的
$("#percentage_input").keyup(function(){
$("#percentage").val($(this).val());
});
it makes me frustate, please give your advice... 这让我感到沮丧,请提供您的建议...
using unique id base on $i in the loop 在循环中基于$ i使用唯一ID
<td><input type='text' id="percentage$i" value='0'></td>
then you can modify your js as 然后您可以将js修改为
$("#percentage_input").keyup(function(){
$("#percentage1").val($(this).val());
});
if you want to to affect all displayed rows, use a class instead of id. 如果要影响所有显示的行,请使用类而不是id。
<td><input type='text' class="percentage" value='0'></td>
$("#percentage_input").keyup(function(){
$(".percentage").val($(this).val());
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.