北京货币兑换社区社区

汇率换算器(select)

刘鹏老师的网络课堂2019-02-23 13:30:23

<html>

<head>

<meta charset="utf-8">

<script type="text/javascript">

function calculate(){

var x=parseFloat(document.getElementById("textfield").value);

var y=parseFloat(document.getElementById("select").value);

var z=parseFloat(document.getElementById("select2").value);

var result= x*y/z;

document.getElementById("result").innerHTML=result;

}

</script>

</head>

<body>

<h1 align="center">汇率计算器 </h1>

<form id="form1" name="form1" method="post">

<table width="380" height="350" border="0" align="center">

<tr>

<td width="160" align="center" valign="middle">请输入要计算的货币</td>

<td width="246" align="center" valign="middle"><input name="textfield" type="text" id="textfield" size="25"></td>

</tr>

<tr>

<td align="center" valign="middle">您输入的货币是</td>

<td align="center" valign="middle"><select name="select" id="select"onchange="calculate()">

<option value="1">人民币</option>

<option value="6.4088">美元</option>

<option value="6.9356">欧元</option>

<option value="0.052">日元</option>

</select></td>

</tr>

<tr>

<td align="center" valign="middle">您要兑换的货币是</td>

<td align="center" valign="middle"><select name="select2" id="select2" onchange="calculate()">

<option value="1">人民币</option>

<option value="6.4088">美元</option>

<option value="6.9356">欧元</option>

<option value="0.052">日元</option>

</select></td><td width="0"></td>

</tr>

<tr>

<td height="109" align="center" valign="middle"></td>

<td align="center" valign="middle"><p id="result" align="center"></p></td>

</tr>

</table>

</form>


</body>

</html>