如何获得Checked Radio按钮的<h3> Tag值?

时间:2017-12-16 06:17:06

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

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>

1 个答案:

答案 0 :(得分: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;
})