Javascript 使用Jquery为1复选框选择查找两个输入值?
我需要从1复选框中检索两个值“price和weight”。我使用jquerymobilecss来实现这一点 我简化了代码,尽可能多地写了出来。我不知道该怎么做 我需要在两个单独的div中单击框后输出。我将使用结果传递给simplecartJS 我的代码Javascript 使用Jquery为1复选框选择查找两个输入值?,javascript,jquery,jquery-mobile,simplecart,Javascript,Jquery,Jquery Mobile,Simplecart,我需要从1复选框中检索两个值“price和weight”。我使用jquerymobilecss来实现这一点 我简化了代码,尽可能多地写了出来。我不知道该怎么做 我需要在两个单独的div中单击框后输出。我将使用结果传递给simplecartJS 我的代码 <!doctype html> <html> <head> <meta charset="utf-8"> <title>TEST LIST</title> <link
<!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>
测试列表
2.0克
$22.00
3.5克
$45.00
7.0克
$90.00
var价格结果;
var加权结果;
$(“??”)单击(函数(){
????
});
$(“.price_results”).html(price_results);
$(“.weight_results”).html(weight_results);
复制和粘贴
这是我的页面
谢谢 试试这个,它应该适合你
$('input[type=radio]')。打开('change',函数(el){
$('.price_results').text($(this.parent().prev().val());
$('.weight_results').text($(this.val());
});代码>
2.0克
$22.00
3.5克
$45.00
7.0克
$90.00
确实有效,在加载页面时是否仍要选择第一个框的值?以防他们不点击任何东西,比如默认值?非常感谢。@Kresimir Pendicalso。。结果是相反的。。我得到了价格的重量。。我会设法解决的,但如果你知道一个快速的方法@kresimir pendicI修复了排序问题,仍然致力于“在页面加载时获取结果”@克雷西米尔·潘迪奇