【问题标题】:How can I get Checked Radio button's <h3> Tag value?如何获取 Checked Radio 按钮的 <h3> 标签值?
【发布时间】:2018-05-30 07:10:28
【问题描述】:

New.html.erb

<div id="monthly_plan">
   <% @monthly_plans.each_with_index do |plan, index| %>
      <div class="col-sm-6">
          <input type="radio" name="subscription[plan_id]" id="plan_<%= plan.try(:id) %>" value="<%= plan.try(:id) %>">
          <label for="plan_<%= plan.try(:id) %>"> <%= plan.try(:name) %><br> </label>
         <h3 id="month_amount_<%= index %>"><%= number_to_currency(plan.try(:amount)) %></h3>
      </div>
   <% end %>
</div>

我得到了选中的单选按钮的标签值?那么,我怎样才能使用 jquery/javascript。

我想在同一页面上显示金额

<div class="order_total">
    <div class="row">                    
        <div class="col-sm-6 text-left">
            <p>ORDER TOTAL:</p>
        </div>

        <div class="col-sm-6 text-right">
            <h4>$00.00</h4> <!-- **Here i want amount so how i can get** -->
        </div>
    </div>
</div>

【问题讨论】:

    标签: javascript jquery ruby-on-rails ruby ajax


    【解决方案1】:

    我在 onchage() 上调用了函数

    $('[name="subscription[plan_id]"]').change(function(){
      var ec = $('[name="subscription[plan_id]"]:checked');
      console.log(ec);
      var amount = $(ec).parent().find("h3").text();
      console.log(amount);
      document.getElementById('total_amount').innerHTML = amount;
    })
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-03-25
      • 1970-01-01
      • 1970-01-01
      • 2019-10-31
      • 2013-07-19
      • 1970-01-01
      相关资源
      最近更新 更多