计算功能 [英] calculation function
本文介绍了计算功能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
展开 | 选择 | Wrap | < span class =codeLinkonclick =LineNumbers(this);>行号
解决方案
Hello Azura。如果不点击按钮,有很多方法可以做到这一点。请你把完整的代码寄给我你正在做的工作。如果您的表单包含三个文本框表示,1表示输入第一个值,2表示输入第二个值,3表示总计。在第二个文本框中,您编写事件onblur =" calculate()"。而你的代码在计算函数。这符合你的要求。如果有任何疑问回复它我会帮助你。
[HTML]< html>
< head>
< script type =" text / javascript">
函数calculate()
{
var total =(parseInt(document) .getElementById(" cam")。value)+ parseInt(document.getElementById(" final_exam")。val ue))/ 2;
document.getElementById(" total")。value =总计;
}
< / script>
< / head>
< body>
输入< input type =" text" id =" cam">< br />
输入b< input type =" text" ID = QUOT; final_exam" onblur =" calculate()">< br />
Total =< input type =" text" id =" total">< br />
< / body>
< / html> [/ HTML]
在函数中我使用parseInt()来获取数据。在javascript中,无论从输入项获得的数据都将默认为String。为了转换我曾经使用它
问候
Ramanan Kalirajan
谢谢......它是'工作,但我把它改成onclick在最后的分数...再次感谢先生...
亲爱的先生...它只在我的数据工作..我可以得到那些工作在很多数据中......比如重复区域??
dear sir..my friend give me one code how to calculate without pressing any button... but i didn''t know how to insert function to make it work... very very newbie in calculation using javascript..please someonehelp me please..
Expand|Select|Wrap|Line Numbers
解决方案
Hello Azura. There are many ways u can do that without clicking a button. can u please send me the full code what u are working at. If your form contains three text box means, 1 for entering the first value, 2 for entering the second value and the 3 for total. in the 2nd text box you write the event onblur="calculate()". And your code in calculate function. That will match ur requirement. if any doubts post back it I will help u out.
[HTML]<html>
<head>
<script type="text/javascript">
function calculate()
{
var total = (parseInt(document.getElementById("cam").value) + parseInt(document.getElementById("final_exam").val ue)) / 2;
document.getElementById("total").value = total;
}
</script>
</head>
<body>
Enter a <input type="text" id="cam"><br/>
Enter b <input type="text" id="final_exam" onblur="calculate()"><br/>
Total = <input type="text" id="total"><br/>
</body>
</html>[/HTML]
In the function I used parseInt() for getting the data. In javascript whatever the data got from input item will be defaultly consider as a String. Inorder to convert I had used it
Regards
Ramanan Kalirajan
thanks.... it''s work but i change it into onclick at the final score... thanks again sir...
dear sir... it work when i data only..how can i get those work in many data... like repeat region??
这篇关于计算功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取
|
15天全站免登陆