请问我的JS代码出了什么问题,为什么按钮按下去没反应?
<styletype="text/css">table{border-collapse:collapse;}td{border:1pxsilversolid;paddin...
<style type="text/css">
table{
border-collapse: collapse;
}
td{
border:1px silver solid;
padding:5px;
font-size: 12px;
}
input{
width: 80px;
}
</style>
<script type="text/javascript">
function converToNumbers(id){
return parseFloat(document.getElementById(id).value);
}
function totalmoney(){
var money=converToNumbers("money");
var years=converToNumbers("years");
var addition=converToNumbers("addition");
var rate=converToNumbers("rate");
rate/=100;
var sum_money=money+(years-1)*addition;
var firstyear=money+money*(1+rate);
var sum=firstyear;
for(int i=1;i<years;i++){
sum+=addition;
sum*=1+rate;
}
document.getElementById("sum_money").value=sum_money;
document.getElementById("sum_profit").value=sum-sum_money;
document.getElementById("moneyAndProfit").value=sum;
}
</script>
<table>
<tr>
<td>起始资金</td><td><input type="text" id="money" value="10000" />¥</td>
</tr>
<tr>
<td>每年收益</td><td><input type="text" id="rate" value="5" />%</td>
</tr>
<tr>
<td>复利年数</td><td><input type="text" id="years" value="10" />年</td>
</tr>
<tr>
<td>每年追加资金</td><td><input type="text" id="addition" value="10000" />¥</td>
</tr>
<tr>
<td colspan="2" align="center"><input type="button" id="calculate" onclick="totalmoney()" value="计算"/></td>
</tr>
<tr>
<td>本金和</td><td><input type="text" id="sum_money" disabled="disabled" />¥</td>
</tr>
<tr>
<td>利息和</td><td><input type="text" id="sum_profit" disabled="disabled" />¥</td>
</tr>
<tr>
<td>本息和</td><td><input type="text" id="moneyAndProfit" disabled="disabled" />¥</td>
</tr>
</table> 展开
table{
border-collapse: collapse;
}
td{
border:1px silver solid;
padding:5px;
font-size: 12px;
}
input{
width: 80px;
}
</style>
<script type="text/javascript">
function converToNumbers(id){
return parseFloat(document.getElementById(id).value);
}
function totalmoney(){
var money=converToNumbers("money");
var years=converToNumbers("years");
var addition=converToNumbers("addition");
var rate=converToNumbers("rate");
rate/=100;
var sum_money=money+(years-1)*addition;
var firstyear=money+money*(1+rate);
var sum=firstyear;
for(int i=1;i<years;i++){
sum+=addition;
sum*=1+rate;
}
document.getElementById("sum_money").value=sum_money;
document.getElementById("sum_profit").value=sum-sum_money;
document.getElementById("moneyAndProfit").value=sum;
}
</script>
<table>
<tr>
<td>起始资金</td><td><input type="text" id="money" value="10000" />¥</td>
</tr>
<tr>
<td>每年收益</td><td><input type="text" id="rate" value="5" />%</td>
</tr>
<tr>
<td>复利年数</td><td><input type="text" id="years" value="10" />年</td>
</tr>
<tr>
<td>每年追加资金</td><td><input type="text" id="addition" value="10000" />¥</td>
</tr>
<tr>
<td colspan="2" align="center"><input type="button" id="calculate" onclick="totalmoney()" value="计算"/></td>
</tr>
<tr>
<td>本金和</td><td><input type="text" id="sum_money" disabled="disabled" />¥</td>
</tr>
<tr>
<td>利息和</td><td><input type="text" id="sum_profit" disabled="disabled" />¥</td>
</tr>
<tr>
<td>本息和</td><td><input type="text" id="moneyAndProfit" disabled="disabled" />¥</td>
</tr>
</table> 展开
2个回答
展开全部
JS哪来的int类型的变量 把init i 改成var i
for(int i=1;i<years;i++)
for(int i=1;i<years;i++)
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询