亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

javascript使函數參數動態化

javascript使函數參數動態化

呼喚遠方 2021-06-14 17:32:29
所以我試圖在我的 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>
查看完整描述

2 回答

?
qq_花開花謝_0

TA貢獻1835條經驗 獲得超7個贊

只需更改小計即可從 html 中獲取值,如下所示


<script type="text/javascript">

function paymentApi(){

    V.init( {

    apikey: "",

    encryptionKey: "",

    paymentRequest:{

        currencyCode: "USD",

        subtotal: document.getElementById('stotal').innerText //Here

    }

    });

</script>


查看完整回答
反對 回復 2021-06-18
?
慕田峪7331174

TA貢獻1828條經驗 獲得超13個贊

<script type="text/javascript">

function paymentApi(){

    var subtotal = parseFloat($("#stotal").text());


    V.init( {

    apikey: "",

    encryptionKey: "",

    paymentRequest:{

        currencyCode: "USD",

        subtotal: subtotal

    }

    });


</script>


查看完整回答
反對 回復 2021-06-18
  • 2 回答
  • 0 關注
  • 203 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號