dongmu2174 2018-02-27 03:42 采纳率: 100%
浏览 46
已采纳

将html表数据传递给函数

I've used this site a ton but this is the first time posting. Please be kind. I'm trying to pass data from an HTML table to a function using onclick. I'm able to pass the entire table using onclick="markPaid(transaction.innterText), but I want to be able to pass the data from the current data row only. My best attempt is onclick="markPaid(thistransaction.innterText)"but results in an undefined variable when passed to the function "markPaid". Hopefully this is a clear explanation of the issue.

            <table id ="transaction" border="1">
            <style>th, td {padding: 10px;}</style>
            <thead>
                <tr>
                    <th><?php echo implode('</th><th>', array_keys(current($transactions))); ?></th>
                    <th></th>
                </tr>
            </thead>
            <tbody>
                <?php foreach ($transactions as $transaction): array_map('htmlentities', $transaction); ?>
                <tr>
                    <td id = "thistransaction"><?php echo implode('</td><td>', $transaction); ?></td>
                    <td><a class ="btn btn-default" href="invoice.php?ID=<?php echo $transaction['transid']; ?>" target = "_blank">Print Invoice</a> </td>
                    <?php if($transaction['paid'] == false): ?>
                        <td><button class = "btn btn-default" onclick="markPaid(thistransaction.innterText)">Mark as Paid</button></td>
                    <?php endif; ?>
                </tr>
                <?php endforeach; ?>
            </tbody>
        </table>
  • 写回答

1条回答 默认 最新

  • dtip91401 2018-02-27 05:44
    关注

    I think you are getting undefined with onclick="markPaid(thistransaction.innterText)" because thistransaction is not unique. You are setting thistransaction as an id on every row of your table in your foreach loop. Try using something unique for each row, maybe the transid you echo to the invoice, $transaction[transid]

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭
  • ¥15 2020长安杯与连接网探
  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么