【问题标题】:Trying to do a simple calculation with a button尝试使用按钮进行简单计算
【发布时间】:2021-12-15 02:55:35
【问题描述】:

对于一个项目,我正在尝试制作一种计算器。我遇到问题的地方是将我的按钮值更改为我希望计算输出的值

这是我的 html 的一小部分,因为它是一张大桌子,但我正在尝试为所有人制作一个像这样的按钮...

<td><span>2</span></td>
<td><input type="text" id="round[2][score]" ></td>
<td><input type="text" id="round[2][rating]" ></td>
<td><input type="text" id="round[2][slope]" ></td>
<td><input type="button" onclick="calculate1()" id="round[2][handicap]" Value="Press"></td>
                    </tr>

这是我为计算所做的函数:

function calculate1() 
{

    round2score = document.getElementById('round[2][score]').value;
    round2rating = document.getElementById('round[2][rating]').value;
    round2slope = document.getElementById('round[2][slope]').value;
    document.getElementById("round[2][handicap]").innerHTML = round2score - round2rating;

}

同样,我的目标是将“按下”更改为计算值。

【问题讨论】:

标签: javascript html calculation


【解决方案1】:

不使用 InnerHTML,而是使用以下设置按钮值:

    document.getElementById("round[2][handicap]").value = String(round2score - round2rating);

这将设置按钮的值,即显示的文本。

【讨论】:

  • 别担心,莎拉,如果您能将此问题标记为已回答,将不胜感激:)
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-10-08
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多