javascript - 如何获取应该显示在 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>
解决方案
您可以为该元素分配一个 id,然后获取该元素的 innerText 值:
<td id="subtotal" class='soratotalsuccess'>10</td>
<script>
const amount = document.getElementById("subtotal").textContent
</script>
也可以通过className来做,但是效率会低一些
document.getElementsByClassName("soratotalsuccess")[0].textContent
推荐阅读
- javascript - AWS Lambda Node.js。mysql 错误“调用退出后无法排队查询”在第二次调用之后:
- async-await - 如何让赛普拉斯等待 .intercept 请求完成?
- selenium-chromedriver - Webdriver IO - 错误:命令“printPage”尚未实现
- php - php 错误消息:可捕获的致命错误:传递给 EIC\EdiBundle\Service\SerialService::validateOrder() 的参数 1 必须是实例
- r - 在 ggplot2 中绘制非数字分类数据
- javascript - AWS Lambda - ValidationException:提供的关键元素与架构不匹配
- html - 使用带有 selenium 的 vba 如何获取表格中的特定单元格然后单击它
- django - 使用 gunicorn 和 nginx 部署 django 应用程序。错误主管:未生成子进程
- asp.net - 了解“System.Net.HttpListenerRequest”处理的异常
- java - 确定事务是否已提交