2013-04-25 54 views
0

我想知道如何设计(边框/色)添加到我的Java脚本添加边框和颜色的JavaScript

我不与代码经验丰富,但可以快速学习

也许一些提示如何添加边框和颜色+盒可以真正帮助

另外,我想答案只有2位小数,而不是无限

谢谢:)

我下面的代码:

<html> 
<head> 
<script type = "text/javascript"> 



function convert() { 
var Amount=document.getElementById('amount'); 
var Currency=document.getElementById('currency'); 
var Converted=document.getElementById('converted'); 
var Choice=document.getElementById('choice'); 
var AED=1; 
var US=0.27; 
var QR=0.99; 
var SR=1.02; 
var KD=0.0778; 
var BD=0.102; 

switch(document.converter.currency.value) { 
case "US Dollars" : 
document.converter.converted.value=US*document.converter.amount.value; 
document.converter.choice.value=document.converter.currency.value; 
break; 
case "Qatar Riyal": 
document.converter.converted.value=QR*document.converter.amount.value; 
document.converter.choice.value=document.converter.currency.value; 
break; 
case "Saudi Riyal": 
document.converter.converted.value=SR*document.converter.amount.value; 
document.converter.choice.value=document.converter.currency.value; 
break; 
case "Kuwaiti Dinar": 
document.converter.converted.value=KD*document.converter.amount.value; 
document.converter.choice.value=document.converter.currency.value; 
break; 
case "Bahrain Dinar": 
document.converter.converted.value=BD*document.converter.amount.value; 
document.converter.choice.value=document.converter.currency.value; 
break; 
} 

} 
</script> 

</head> 

<body> 
<div id="divWrapper"> 
<form name="converter" id="converter"> 
Enter amount in UAE Dirhams AED 
<input name="amount"type="text" id="amount" size="7" /> 
<br /><br /> 
Please select a currency <select name="currency" id="currency"> 
<option>Please Choose One</option> 
<option value="US Dollars">US Dollars</option> 
<option value="Qatar Riyal">Qatar Riyal</option> 
<option value="Saudi Riyal">Saudi Riyal</option> 
<option value="Kuwaiti Dinar">Kuwaiti Dinar</option> 
<option value="Bahrain Dinar">Bahrain Dinar</option> 
</select><br /><br /> 
The amount is: 
<input name="converted" type="text" id="converted" value="" size="7"/> 
in 
<input name="choice" type="text" id="choice" style="border:0px" value=""> 
<br /><br /> 
<input type="button" name="convt" id="convt" onclick="convert()" value="Convert" /> 
</form> 
</div> 
</body> 
</html> 
+1

我认为这[链接](http://www.w3schools.com/css/css_border.asp)可以帮助你在你的问题。 – StackOverflowUser 2013-04-25 07:50:26

+0

太棒了,谢谢你:) – nadz 2013-04-25 07:55:25

+0

很高兴知道!不客气! – StackOverflowUser 2013-04-25 07:56:47

回答

0
<html> 
<head> 

    <script type="text/javascript"> 



     function convert() { 
      var Amount = document.getElementById('amount'); 
      var Currency = document.getElementById('currency'); 
      var Converted = document.getElementById('converted'); 
      var Choice = document.getElementById('choice'); 
      var AED = 1; 
      var US = 0.27; 
      var QR = 0.99; 
      var SR = 1.02; 
      var KD = 0.0778; 
      var BD = 0.102; 

      switch (document.converter.currency.value) { 
       case "US Dollars": 
        var x = US * document.converter.amount.value; 
        document.converter.converted.value = x.toFixed(2); 
        document.converter.choice.value = document.converter.currency.value; 
        break; 
       case "Qatar Riyal": 
        var x = QR * document.converter.amount.value; 
        document.converter.converted.value = x.toFixed(2); 
        document.converter.choice.value = document.converter.currency.value; 
        break; 
       case "Saudi Riyal": 
        var x = SR * document.converter.amount.value; 
        document.converter.converted.value = x.toFixed(2); 
        document.converter.choice.value = document.converter.currency.value; 
        break; 
       case "Kuwaiti Dinar": 
        var x = KD * document.converter.amount.value; 
        document.converter.converted.value = x.toFixed(2); 
        document.converter.choice.value = document.converter.currency.value; 
        break; 
       case "Bahrain Dinar": 
        var x = BD * document.converter.amount.value; 
        document.converter.converted.value = x.toFixed(2); 
        document.converter.choice.value = document.converter.currency.value; 
        break; 
      } 
     } 
    </script> 

</head> 
<body> 
    <div id="divWrapper"> 
     <form name="converter" id="converter"> 
     Enter amount in UAE Dirhams AED 
     <input name="amount" type="text" id="amount" size="7" /> 
     <br /> 
     <br /> 
     Please select a currency 
     <select name="currency" id="currency"> 
      <option>Please Choose One</option> 
      <option value="US Dollars">US Dollars</option> 
      <option value="Qatar Riyal">Qatar Riyal</option> 
      <option value="Saudi Riyal">Saudi Riyal</option> 
      <option value="Kuwaiti Dinar">Kuwaiti Dinar</option> 
      <option value="Bahrain Dinar">Bahrain Dinar</option> 
     </select><br /> 
     <br /> 
     The amount is: 
     <input name="converted" type="text" id="converted" value="" size="7" /> 
     in 
     <input name="choice" type="text" id="choice" style="border: 0px" value="" /> 
     <br /> 
     <br /> 
     <input type="button" name="convt" id="convt" onclick="convert()" value="Convert" /> 
     </form> 
    </div> 
</body> 
</html> 
+0

在这里,@nadz试试这个 – StackOverflowUser 2013-04-26 06:11:38