2013-03-09 74 views
0

我想提示,將取代值改變HTML元素值

<html> 
    <body> 
     <a href="http://249lease.webs.com/" class="dwolla_button" data-name="Lease" data-desc="Payments" data-amount="5" data-shipping="0"    data-tax="0" data-guest-checkout="true" data-key="sHqCOc31Vh3JiAsPhBfEk5f4D9bAWKLzwaT06ah3Aw65i0gkZl">Bank Account (25¢)</a> 
     <script type="text/javascript" src="https://www.dwolla.com/scripts/button.min.js"> </script> 
    </body> 
</html> 

我添加

<script type="text/javascript"> 
    document.getElementByClass("dwolla_button")[0].setAttribute("data-amount", "43"); 
</script> 

,並試圖將整個事情「數據量」的值在下面的腳本中沒有任何成功的想法?

<html> 
    <body> 
     <a href="http://249lease.webs.com/" class="dwolla_button" data-name="Lease" data-desc="Payments" data-amount="5" data-shipping="0"    data-tax="0" data-guest-checkout="true" data-key="sHqCOc31Vh3JiAsPhBfEk5f4D9bAWKLzwaT06ah3Aw65i0gkZl">Bank Account (25¢)</a> 
     <script type="text/javascript"> 
      document.getElementByClass("dwolla_button")[0].setAttribute("data-amount", "43"); 
     </script> 

     <script type="text/javascript" src="https://www.dwolla.com/scripts/button.min.js"> </script> 
    </body> 
</html> 

回答

1

從getElementByClassName你的方法更改爲getElementsByClassName

document.getElementsByClassName("dwolla_button")[0].setAttribute("data-amount", "43"); 
+0

感謝這麼多,小錯誤犯大錯誤。 – 2013-03-09 21:08:49

+0

您可能如何製作,以便用戶必須輸入該值? – 2013-03-09 21:30:15