繁体   English   中英

从中获取数据 <td> 在由行ID指定的同一表行上执行计算

[英]Get data from <td> on the same table row specified by row id and perform computation

我有一个html表,其中填充了来自mysql数据库的数据。 结构如下:

<table>    
<?php
foreach($prods as $key=>$p){
?>
   <tr class="row1" id="tr<?php echo $p['ProductID']?>">
   <td id="pid<?php echo $p['ProductID']?>"><?php echo $p['ProductID']?></td>
   <td id="pname<?php echo $p['ProductID']?>"><?php echo $p['ProductName'];?></td>
   <td id="pdesc<?php echo $p['ProductID']?>"><?php echo $p['ProductDesc'];?></td>
   <td id="pprice<?php echo $p['ProductID']?>"><?php echo $p['UnitPrice'];?></td>
   <td><input type="checkbox" id="chk<?php echo $p['ProductID']?>" checked></td>
   <td><input type="text" style="width:50px;" onkeyup="getall(this);" id="<?php echo    $p['ProductID']?>"></td>
   <td><input type="text" style="width:50px;" id="total<?php echo $p['ProductID']?>">    </td>
   <span id="ttl" name="ttl"> 0.00</span>
   </tr>
   <?php
   }
   ?>
   </table>

我没有问题填充表格,但是每次用户更改<input type="text" style="width:50px;" onkeyup="getall(this);" id="<?php echo $p['ProductID']?>"></td>值时,我都需要更新<span id="ttl"><input type="text" style="width:50px;" onkeyup="getall(this);" id="<?php echo $p['ProductID']?>"></td> <input type="text" style="width:50px;" onkeyup="getall(this);" id="<?php echo $p['ProductID']?>"></td> <input type="text" style="width:50px;" onkeyup="getall(this);" id="<?php echo $p['ProductID']?>"></td> 我做了一个Javascript函数,但是我做不到我想要的。

范围的值应为<td id="pprice<?php echo $p['ProductID']?>"><?php echo $p['UnitPrice'];?></td>用户在文本框中输入的数量。

填写完所有字段后,我很快会将这些数据保存回数据库中。

如果是正确使用不知道。 只需尝试类似:

<input type="text" style="width:50px;" onkeyup="getall('<?php echo $p['ProductID']?>');" id="<?php echo $p['ProductID']?>"></td>

并在您的javascript函数中:

function getall(strId)
{
    var tmpObj = document.getElementById(strId);
    alert("reported id for testing: " + tmpObj.getAttribute("id"));
}

试试看

暂无
暂无

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

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