我正在编写一个表单,用于从框中获取数据,并在单击“计算”按钮时进行计算。 该按钮通过函数cal()进行计算,但不能在countfield框中显示结果。 如何在框中显示结果? 另外,如何用“ - ”命名该函数?
<script type="text/javascript"> function cal() { var hour = document.getElementById( "hourfield" ).value; var fee = document.getElementById( "feefield" ).value; var count = document.getElementById( "countfield" ).value; count = hour + fee; } </script>I am writing a form to get data from boxes and do a calculation when the "Calculate" button is clicked. The button does the calculation through the function cal(), but it cannot display the result in the countfield box. How the display the result in the box? Also, how the name the function with "-"?
<script type="text/javascript"> function cal() { var hour = document.getElementById( "hourfield" ).value; var fee = document.getElementById( "feefield" ).value; var count = document.getElementById( "countfield" ).value; count = hour + fee; } </script>最满意答案
更改以下内容:
var count = document.getElementById( "countfield" ).value; count = hour + fee;至:
document.getElementById( "countfield" ).value = hour + fee;这是因为对count变量的任何赋值都会改变它的引用而不是表单中的字段。 而且名称中不能包含“ - ”,但可以使用“_”或单词“minus”。
Change the following:
var count = document.getElementById( "countfield" ).value; count = hour + fee;to:
document.getElementById( "countfield" ).value = hour + fee;That's because any asignment to the count variable just changes it's reference and not the field in the form. And you cannot have "-" in the name, but you can use "_" or word "minus".
更多推荐
cal,function,countfield,函数,电脑培训,计算机培训,IT培训"/> <meta name="de
发布评论