2013-03-09 64 views
0

的元素我有一個腳本與「數據量」提示輸入值,並用它在HTML

<html> 

    <body> 

     <script>"prompt('Please enter your name','')"</script> 

     <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.getElementsByClassName("dwolla_button")[0].setAttribute("data-amount", "43") 


     </script> 

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




    </body> 

</html> 

我想提示「數據量的價值變化值「所以我嘗試了下面的腳本,它爲我稱爲XxX的變量添加了一個提示,我現在如何在我的Javascript中使用該變量?

<html> 

    <body> 

     <script>"prompt('Please enter your name','')"</script> 

     <a href="http://249lease.webs.com/" class="dwolla_button" data-name="Lease" data-desc="Payments" data-amount="4" data-shipping="0"    data-tax="0" data-guest-checkout="true" data-key="sHqCOc31Vh3JiAsPhBfEk5f4D9bAWKLzwaT06ah3Aw65i0gkZl">Bank Account (25¢)</a> 


     <script type="text/javascript"> 

     var XxX= prompt("amount", ""); 


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


     </script> 

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




    </body> 

</html> 

回答

0

刪除變量名稱周圍的引號。在單引號或雙引號之間添加任何內容會導致它被用作字符串文字:

var XxX = prompt("amount"); 
document.getElementsByClassName("dwolla_button")[0].setAttribute("data-amount", XxX);