我需要从1复选框中检索两个值“价格和重量”。我正在使用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;">$22.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;">$45.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;">$90.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
感谢!!!
答案 0 :(得分:0)
试试这个,这应该适合你,
$('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;">$22.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;">$45.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;">$90.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>