使用jquery从单选按钮获取跨度价格

时间:2016-09-29 08:14:42

标签: javascript jquery html

我有班级.amount,现在我想从跨度中获取价格

 $('.dimension-layer-dimension').click(function() {
   // I am trying with this javascript
   var price4 = $(this).find('radio:checked').data('price')
   $('span.amount').text(price);
   alert(price4);
 });
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>

<li class="radio">
  <input class="tmcp-field dimension-layer-dimension tm-epo-field tmcp-radio" name="tmcp_radio_9" data-price="" type="radio">
  <label for="tmcp_choice_9_0_17">72*30</label>
  <span class="price tc-price  hidden">
       <span class="amount">1000</span>
  </span>
</li>

1 个答案:

答案 0 :(得分:2)

您应该使用遍历到普通父li.radio,然后使用.find()来获取元素。

要使文字.text()并设置.text(newValue)

 $('.dimension-layer-dimension').click(function() {
    var spanEl = $(this).closest('li.radio').find('span.amount');
    var price = spanEl.text(); //Get text
 });