我目前有一个接受可变金额付款的捐赠表格。 我已经将 Stripe 作为付款方式,现在想包括 PayPal。
为了将捐赠金额传递给 Stripe,我使用了这个方法,因为表单是用 JavaScript 编写的
var amount = document.querySelector('.total-box > span').innerText;
我还像这样向用户显示总金额:
<span class="total-box"><span></span></span>
我需要知道如何将上面的 var amount
或 span class
添加到 PayPal 按钮上这个隐藏输入字段的金额值:
<input type="hidden" name="amount" value="">
如有任何帮助,我们将不胜感激。
最佳答案
在输入元素上使用点符号,hidden.value
var amount = document.querySelector('.total-box > span').innerText;
var hidden = document.querySelector("input[name='amount']");
hidden.value = amount;
console.log("Value of hidden input:", hidden.value);
<span class="total-box"><span>3</span></span>
<input type="hidden" name="amount" value="">
关于javascript - 将金额值添加到表单输入值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49398199/