gpt4 book ai didi

javascript - 输入总和问题

转载 作者:太空宇宙 更新时间:2023-11-03 18:20:20 25 4
gpt4 key购买 nike

我在 rails 中使用 javascript 在另一个输入中显示了一个应用程序

这是我的 Controller

 def
@soles = Client.sum(:money)
end

这是我的观点,我正在显示 @soles 的结果并尝试将 @soles 与我将写入 input2 的值相加,它应该显示在我的输入总和上。

问题是我在一个只有总和的新页面中得到总和(没有显示在输入总和上)

 <input type="text" id="my_input1" value="<%=  @soles  %>" />
<input type="text" id="my_input2" onchange="doMath();" />
<input type="text" id="sum" />

<script type="text/javascript">
function doMath()
{
// Capture the entered values of two input boxes
var my_input1 = document.getElementById('my_input1').value;
var my_input2 = document.getElementById('my_input2').value;

// Add them together and display
var sum = parseInt(my_input1) + parseInt(my_input2);
document.write(sum);
}

我非常感谢帮助谢谢

最佳答案

代替

document.write(sum);

使用

document.getElementById('sum').value = sum;

关于javascript - 输入总和问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19553660/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com