为JavaScript添加边框和颜色

时间:2013-04-25 07:44:45

标签: javascript

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

我对代码没有经验,但可以快速学习

关于如何添加边框和颜色+盒子的一些提示可能真的有帮助

另外,我希望答案只有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 个答案:

答案 0 :(得分: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>