【问题标题】:get value of element which attached to radio获取附加到收音机的元素的值
【发布时间】:2016-11-06 09:51:10
【问题描述】:

当我使用 jQuery 在一对单选按钮中选择一个单选时,如何获得 .coefficient 的值?

<label class="bet-team-box" for="radio-1">
    <input class="bet-main-input" id="radio-1" name="group1" type="radio">
    <span class="fake-label">
        <span class="team">
            Midnight Sun Esports
        </span>
        <span class="img-box">
            <img src="images/logo-team-04.png" alt="image description" width="20" height="20" />
        </span>
        <span class="coefficient">
            12.43
        </span>
    </span>
</label>

【问题讨论】:

    标签: javascript jquery input radio-button label


    【解决方案1】:

    您可以使用closest() 获取父label 元素,然后使用find() 获取coefficient。试试这个:

    $('.bet-main-input').change(function() {
        var coefficient = $(this).closest('label').find('.coefficient').text();
        // use variable here...
    });
    

    【讨论】:

      【解决方案2】:

      不确定它是否是最佳方式,但您可以像这样找到它。

       $("#radio-1").click(function()
       {
         $($($(this).siblings()[0]).children('span.coefficient')).text();
      });
      

      【讨论】:

        猜你喜欢
        • 2013-10-20
        • 2018-11-29
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2015-07-29
        • 2015-04-10
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多