所以我试图在我的 order.html 页面上包含支付 API 结帐,但是,您必须在 HTML 文档的头部添加一个脚本。在脚本中,您必须将小计金额指定为数字,但我需要此值是动态的。 “合计”是小计金额。我需要将小计设置为“总计”是什么。我该怎么做?
<head>
<script type="text/javascript">
function paymentApi() {
V.init({
apikey: "",
encryptionKey: "",
paymentRequest: {
currencyCode: "USD",
subtotal: "11.00"
}
});
</script>
</head>
<body>
<p id="sub-total">
<strong>Total</strong>: <span id="stotal"></span>
</p>
最佳答案
只需更改小计即可从 html 中获取值,如下所示
<script type="text/javascript">
function paymentApi(){
V.init( {
apikey: "",
encryptionKey: "",
paymentRequest:{
currencyCode: "USD",
subtotal: document.getElementById('stotal').innerText //Here
}
});
</script>
关于javascript使函数参数动态化,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56421763/