javascript使函数参数动态化

所以我试图在我的 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>


呼唤远方
浏览 183回答 2
2回答

qq_花开花谢_0

只需更改小计即可从 html 中获取值,如下所示<script type="text/javascript">function paymentApi(){&nbsp; &nbsp; V.init( {&nbsp; &nbsp; apikey: "",&nbsp; &nbsp; encryptionKey: "",&nbsp; &nbsp; paymentRequest:{&nbsp; &nbsp; &nbsp; &nbsp; currencyCode: "USD",&nbsp; &nbsp; &nbsp; &nbsp; subtotal: document.getElementById('stotal').innerText //Here&nbsp; &nbsp; }&nbsp; &nbsp; });</script>

慕田峪7331174

<script type="text/javascript">function paymentApi(){&nbsp; &nbsp; var subtotal = parseFloat($("#stotal").text());&nbsp; &nbsp; V.init( {&nbsp; &nbsp; apikey: "",&nbsp; &nbsp; encryptionKey: "",&nbsp; &nbsp; paymentRequest:{&nbsp; &nbsp; &nbsp; &nbsp; currencyCode: "USD",&nbsp; &nbsp; &nbsp; &nbsp; subtotal: subtotal&nbsp; &nbsp; }&nbsp; &nbsp; });</script>
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

JavaScript