如何获得Checked Radio按钮 Tag value?

问题描述 投票:-3回答:1

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个回答
1
投票

我在onchange()上调用了函数

$('[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;
})
© www.soinside.com 2019 - 2024. All rights reserved.