我有一个表,其中显示了一些值。每行中都有一个Order_ID和一个按钮。

如何在单击按钮时获取$ Order_ID中的值以显示(提示)?

<tbody>

<?php

foreach($menuextra_result as $transaction)
{
?>
<tr>



$order_id = isset($transaction['order_id'])?($transaction['order_id']) :"";
?>
<?php if($order_id){ ?>
<td><div id="orderID"><?= $order_id ?></a></td>
<?php } else {?>
<td><div ><span style="color:red">MANGLER</span></td>
<?php }?>



style="color:red">MISSING</span></td>

                        <?php }?>

//There's more here, but did not bother to show it, because it was irrelevant.

<td><input type="submit" onclick="getElementById" value="Yes  "></td>
<?php }
?>

</tr>
<?php
}
?>

</tbody>


这就是我尝试过的方式

<script type="text/javascript">
function getElementById()
{
    el = document.getElementById('order_id');
       alert(el);

}
</script>


但是当点击一个按钮时,什么也没发生

最佳答案

table.php

//assuming you have done you loop work
<table>
<tr>
<td>
<?php echo $row['name']?>
</td>
<td><input type="button" value="click me" onclick="clickMe(<?php echo $row['id']?>)" /></td>
</tr>
</table>


clickme功能是这样的

function clickMe(id) {
alert(id);
}


您将一个参数传递给clickMe()函数,该参数为id

关于php - 单击按钮即可从表中获取值(value),我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/16808538/

10-13 09:10
查看更多