首页 > 解决方案 > 如何获取应该显示在 JavaScript 表格中的数字的值

问题描述

我需要在表 td sub total 中显示的任何值来显示脚本的数量。目的是处理支付商家的内联代码中的总小计金额。如果有一个代码也可以用 html 来捕获这些数据,那将不胜感激

<script src="https://api.ravepay.co/flwv3-pug/getpaidx/api/flwpbf-inline.js"></script>
    <button type="button" onClick="payWithRave()">Pay Now</button>
</form>

<script>
    const API_publicKey = "FLWPUBK-7991a166b25a84cbfb0cdc0deaa78c1f-X";
var selector = document.getElementsByClassName()
    function payWithRave() {
        var x = getpaidSetup({
            PBFPubKey: API_publicKey,
            customer_email: "user@example.com",
            amount: 20,
            customer_phone: "234099940409",
            currency: "NGN",
            txref: "rave-123456",
            meta: [{
                metaname: "flightID",
                metavalue: "AP1234"
            }],
            onclose: function() {},
            callback: function(response) {
                var txref = response.data.txRef; // collect txRef returned and pass to a                    server page to complete status check.
                console.log("This is the response returned after a charge", response);
                if (
                    response.data.chargeResponseCode == "00" ||
                    response.data.chargeResponseCode == "0"
                ) {
                    // redirect to a success page
                } else {
                    // redirect to a failure page.
                }

                x.close(); // use this to close the modal immediately after payment.
            }
        });
    }
<div class='sora_order'>
<table>
<tbody>
<tr>
<th>Selected Payment Method</th>
<td class='soramethodsuccess'/>
</tr>
<tr>
<th>Order ID</th>
<td class='soraorderidsuccess'/>
</tr>
<tr>
<th>Order date</th>
<td class='soraorderdate'>
</td>
</tr>
<tr>
<th>Your Subtotal</th>
<td class='soratotalsuccess'> </td>
</tr>
</tbody>
</table>
  </div>
 
 <form>
   
</script>
  
  

标签: javascripthtml

解决方案


您可以为该元素分配一个 id,然后获取该元素的 innerText 值:

<td id="subtotal" class='soratotalsuccess'>10</td>

<script>
const amount = document.getElementById("subtotal").textContent
</script>

也可以通过className来做,但是效率会低一些

document.getElementsByClassName("soratotalsuccess")[0].textContent

推荐阅读