【问题标题】:Input sum issue输入总和问题
【发布时间】:2013-10-23 22:41:19
【问题描述】:

我在 Rails 中做了一个应用,使用 javascript 在另一个输入中显示

这是我的控制器

 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.getElementById('sum').value = sum 而不是 document.write(sum)

标签: javascript ruby-on-rails ruby ruby-on-rails-3 ruby-on-rails-3.2


【解决方案1】:

代替

document.write(sum);

使用

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-08-15
    • 2021-01-22
    • 2015-11-28
    • 2021-08-26
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多