如何使用javascript设置eWay值属性

时间:2016-01-30 08:07:19

标签: javascript

我有这段代码:

<script src="https://secure.ewaypayments.com/scripts/eCrypt.js"
   class="eway-paynow-button"
   data-publicapikey=""
   data-amount="1000"
   data-currency="AUD" >
</script>

如何从Javascript函数设置数据量?

3 个答案:

答案 0 :(得分:1)

你可以试试

(假设你只有脚本元素eway-paynow-button

document.getElementsByClassName("eway-paynow-button")[0].dataset.amount = 1000;

或更通用的解决方案

var elems = document.getElementsByClassName("eway-paynow-button");
for (var i = 0; i < elems.length; i++) {
   if(elems[i].getAttribute('src') === "https://secure.ewaypayments.com/scripts/eCrypt.js") {
      elems[i].dataset.amount = 1000;
   }
}

答案 1 :(得分:0)

您可以使用我的jQuery解决方案来更改按钮文字问题

<!DOCTYPE>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>X</title>
</head>
 <body>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3/jquery.min.js"></script>
<script src="https://secure.ewaypayments.com/scripts/eCrypt.js"
   class="eway-paynow-button"
   data-publicapikey=""
   data-amount="1000"
   data-currency="AUD" >
</script>
    <script type="text/javascript">
    // jQuery Document
        $(document).ready(function(){
            $(".eway-paynow-button").attr("data-amount",2000);
        });
    </script>
</body>
</html>

答案 2 :(得分:0)

要扩展nikhil的解决方案,您可以像这样更改文本:

document.getElementsByClassName("eway-paynow-button")[0].setAttribute("data-amount", "2000");
document.getElementsByClassName("eway-button")[0].firstElementChild.innerHTML = "Pay Now ($20.00)";