为什么我的按钮上的功能不起作用?(Why does the function on my button not work?)

编程入门 行业动态 更新时间:2024-10-28 04:27:06
为什么我的按钮上的功能不起作用?(Why does the function on my button not work?)

我正在编写一个表单,用于从框中获取数据,并在单击“计算”按钮时进行计算。 该按钮通过函数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

本文发布于:2023-07-26 06:55:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1272214.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:按钮   不起作用   功能   work   function

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!