功能问题Javascript Sum [英] Problem with function Javascript Sum

查看:74
本文介绍了功能问题Javascript Sum的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好。


我有这个功能:

展开 | 选择 | 换行 | 行号

解决方案

嗨...


欢迎来到TSDN ......


i认为不是以你想要的方式工作。请显示与此问题相关的html ...因为我认为nelementi应该是您的表单中包含的一些文本框?


亲切的问候


< blockquote>嗨


好​​吧,我认为你的代码中存在逻辑错误,但我可以看到你想要做什么。所以我为你编写代码。我希望它你想要的。


[HTML]


<!DOCTYPE HTML PUBLIC" - // W3C // DTD HTML 4.01 Transitional // EN"

" http://www.w3.org/TR/html4/loose.dtd">

< html>

< head>

< title> Untitled Document< / title>

< meta http-equiv =" Content-Type"含量=" text / html的; charset = utf-8">

< / head>


< body>

< form id = " form1">

< input type =" text" ID = QUOT; Totale_imponibile_1"值= QUOT; 50" />< br />

< input type =" text" ID = QUOT; Totale_imponibile_2"值= QUOT; 2英寸/>< br />

< input type =" text" ID = QUOT; Totale_imponibile_3"值= QUOT; 3英寸/>< br />

< input type =" text" ID = QUOT; somma_totale_imponibile"值= QUOT;" />< br />

< input type =" button" value =" Sum Up"的onClick = QUOT; calcola(3);" />

< / form>

< / body>


< script language =" javascript" >

函数calcola(长度)

{

// Somma Totale Imponibile

var somma_totale_imponibile = 0;

for(var id = 1; id< = length; id ++)

{

var temp = document.getElementById(" Totale_imponibile_" ; + id).value;

if(isNaN(temp)== false)

somma_totale_imponibile + = parseFloat(temp);

}

// alert(somma_totale_imponibile);

document.getElementById(" somma_totale_imponibile")。value = somma_totale_imponibile.toFixed(2);

}

< / script>

< / html>



[/ HTML ]


希望它有所帮助。


感谢您的帮助,但很抱歉我无法使用代码。


地址页面htm:
http ://users2.titanichost.com/garza/

Hi there.

I have this Function:

Expand|Select|Wrap|Line Numbers

解决方案

hi ...

welcome to TSDN ...

i think that doesn''t work the way you intended. please show your html relating to this problem too ... because i assume nelementi should be a number of textboxes contained by your form?

kind regards


hi

well,I think there''s a logical error in your code,but I can see what you want to do.so I write a code for you.I hope it''s you want.

[HTML]

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>

<body>
<form id="form1">
<input type="text" id="Totale_imponibile_1" value="50" /><br />
<input type="text" id="Totale_imponibile_2" value="2" /><br />
<input type="text" id="Totale_imponibile_3" value="3" /><br />
<input type="text" id="somma_totale_imponibile" value="" /><br />
<input type="button" value="Sum Up" onClick="calcola(3);" />
</form>
</body>

<script language="javascript">
function calcola(length)
{
//Somma Totale Imponibile
var somma_totale_imponibile = 0;
for ( var id = 1; id <= length; id++ )
{
var temp = document.getElementById("Totale_imponibile_" + id).value;
if (isNaN(temp) == false)
somma_totale_imponibile += parseFloat(temp);
}
//alert(somma_totale_imponibile);
document.getElementById("somma_totale_imponibile") .value = somma_totale_imponibile.toFixed(2);
}
</script>
</html>



[/HTML]


hope it helps.


Thanks for you help, but sorry iam unable to work code.

Address page htm:
http://users2.titanichost.com/garza/


这篇关于功能问题Javascript Sum的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆