使用 Jquery 为 1 个复选框选择查找两个输入值?

Using Jquery to find two input values for 1 checkbox selection?

我需要从 1 个复选框中检索两个值 "price and weight" 。为此,我正在使用 Jquery Mobile CSS。

我简化了代码并尽可能多地写出来。我不知道如何处理这个问题。

单击框后,我需要在两个单独的 div 中输出。我将使用结果传递给 simplecartJS。

我的代码

<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>TEST LIST</title>
<link rel="stylesheet" href="https://code.jquery.com/mobile/1.4.5/jquery.mobile-1.4.5.min.css">
<script src="https://code.jquery.com/jquery-1.11.3.min.js"></script>
<script src="https://code.jquery.com/mobile/1.4.5/jquery.mobile-1.4.5.min.js"></script>
<script src="simpleCart.js"></script>
</head>
<body>
<fieldset id="" class="" style="margin-top: 0px;font-variant: small-caps;letter-spacing: 2px;" data-role="controlgroup">

    <input class="weight1" type="hidden" value="2.0" >
    <input class="price1" type="radio" name="radio-choice-v-2" id="radio-choice-v-2a" value="20.00" checked="checked">
    <label class="price_weight_lable1" style="display: flex;" for="radio-choice-v-2a">
        <div style="flex:2;">2.0 grams</div>
        <div style="flex:1;text-align: center;">.00</div>
    </label>


    <input class="weight2" type="hidden" value="3.5" >
    <input class="price2" type="radio" name="radio-choice-v-2" id="radio-choice-v-2b" value="45.00">
    <label class="price_weight_lable2" style="display: flex;" for="radio-choice-v-2b">
        <div style="flex:2;">3.5 grams</div>
        <div style="flex:1;text-align: center;">.00</div>
    </label>


   <input class="weight3" type="hidden" value="7.0" >
    <input class="price3" type="radio" name="radio-choice-v-2" id="radio-choice-v-2c" value="90.00">
    <label class="price_weight_lable3" style="display: flex;" for="radio-choice-v-2c">
        <div style="flex:2;">7.0 grams</div>
        <div style="flex:1;text-align: center;">.00</div>
  </label>  
</fieldset>

    <script>
     var price_results;
     var weight_results;

        $("????").click(function(){
        ????            
});

        $(".price_results").html( price_results );
        $(".weight_results").html( weight_results );
    </script>




<div class="simpleCart_shelfItem">


    <div class="item_price"> <!-- simplecart div -->    
        <div class="price_results"></div> <!-- price function result? -->                          
    </div>

     <div class="item_weight"> <!-- simplecart div -->   
        <div class="weight_results"></div>   <!-- weight function result? -->                        
    </div>


</div>

</body>
</html>

复制粘贴。

这是我的页面 www.aarontomlinson.com

谢谢!!!

试试这个,应该适合你,

$('input[type=radio]').on( 'change', function(el){
  $( '.price_results' ).text( $(this).parent().prev().val() );
  $( '.weight_results' ).text( $(this).val() );
});
<link href="https://code.jquery.com/mobile/1.4.5/jquery.mobile-1.4.5.min.css" rel="stylesheet"/>
<script src="https://code.jquery.com/jquery-1.11.3.min.js"></script>
<script src="https://code.jquery.com/mobile/1.4.5/jquery.mobile-1.4.5.min.js"></script>


<fieldset id="" class="" style="margin-top: 0px;font-variant: small-caps;letter-spacing: 2px;" data-role="controlgroup">

    <input class="weight1" type="hidden" value="2.0" >
    <input class="price1" type="radio" name="radio-choice-v-2" id="radio-choice-v-2a" value="20.00" checked="checked">
    <label class="price_weight_lable1" style="display: flex;" for="radio-choice-v-2a">
        <div style="flex:2;">2.0 grams</div>
        <div style="flex:1;text-align: center;">.00</div>
    </label>


    <input class="weight2" type="hidden" value="3.5" >
    <input class="price2" type="radio" name="radio-choice-v-2" id="radio-choice-v-2b" value="45.00">
    <label class="price_weight_lable2" style="display: flex;" for="radio-choice-v-2b">
        <div style="flex:2;">3.5 grams</div>
        <div style="flex:1;text-align: center;">.00</div>
    </label>


   <input class="weight3" type="hidden" value="7.0" >
    <input class="price3" type="radio" name="radio-choice-v-2" id="radio-choice-v-2c" value="90.00">
    <label class="price_weight_lable3" style="display: flex;" for="radio-choice-v-2c">
        <div style="flex:2;">7.0 grams</div>
        <div style="flex:1;text-align: center;">.00</div>
  </label>  
</fieldset>


<div class="simpleCart_shelfItem">


    <div class="item_price"> <!-- simplecart div -->    
        <div class="price_results"></div> <!-- price function result? -->                          
    </div>

     <div class="item_weight"> <!-- simplecart div -->   
        <div class="weight_results"></div>   <!-- weight function result? -->                        
    </div>


</div>