js多个输入框运算计算结果输出到另一个输入框

时间:2022-11-02 21:56:33

 

<div id="ckjrzy_4_14_15">
<div id="ckjrzy_4_14_17">收益计算器
</div>
<div id="ckjrzy_4_14_30">
<img src="images/zy/官方网改版---首页-2016_55_副本.jpg" />
</div>
周期:<input id="zhouqi" type="text" name="zhouqi" />天
投资金额: <input id="22" type="text" name="jine" />元
年化利率: <input id="33" type="text" name="nianhua" />%
<input id="114" type="button" name="jisuan" value="=" onclick="myFunction()"/>
预计收益: <input id="shouyi" type="text" name="shouyi" value="" />
元 </div> <input id="shouyi" type="text" name="shouyi2" value="" />
<script type="text/javascript"> function myFunction(){
var zhouqi=document.getElementById("zhouqi").value;
var jine=document.getElementById("22").value;
var nianhua=document.getElementById("33").value;
var sum = parseInt(nianhua)/365/100*parseInt(jine)*parseInt(zhouqi);
document.getElementById("shouyi").value=sum;
} </script>

 

<script language="javascript" type="text/javascript">
<!--
function f1(){
var num1 = document.getElementsByTagName('input')[0].value;
var num2 = document.getElementsByTagName('input')[1].value;
var sum = parseInt(num1)+parseInt(num2);
alert('和为:'+ sum);
}
//-->
</script>
</head>
<body>
<input type="text"/><br />
<input type="text"/><br />
<input type="button" value="求和" onclick="f1()"/>
</body>