我有基本的HTML代码

<div class="w-input-number-change">
    <input class="other-select input-number-change" type="radio" data-price="110" data-value="I will supply ___ pages of typed content" name="copy">
    I will supply
    <input class="other-select input-number-change-value" type="number" data-price="110" data-value="pages of typed content" name="copy" value="1">
    pages of typed content.
</div>


我得到值输入型收音机

$content_radio =  $('.input-number-change').data('value');


我将选择输入类型单选,显示“我将提供_页的输入内容”,其中_是输入类型number的值。单击输入单选框时如何从显示的输入数字中获取价值?

最佳答案

从输入中删除data-value,您可以很容易地获得它,如下所示:

DEMO

的HTML

<div class="w-input-number-change">
        <input class="other-select input-number-change" type="radio" data-price="110" name="copy"/>
         I will supply
        <input class="other-select input-number-change-value" type="number" data-price="110" data-value="pages of typed content" name="copy" value="1"/>
        pages of typed content.
</div>


JS

$('.input-number-change').on('click',function(){
    var value=$(this).siblings('.input-number-change-value').val();
    alert('I will supply '+value +' pages of typed content')
});

09-30 16:18
查看更多