改变html元素值

时间:2013-03-09 21:03:34

标签: html getelementsbyclassname

我正在尝试提示替换“data-amount”

值的值
<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 个答案:

答案 0 :(得分:1)

将您的方法从getElementByClassName更改为getElementsByClassName

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