这是我的代码:HTML
<div>
<p>Whatsit:<span class="price"></span></p>
<p>Whosit: <span class="whositprice"></span></p>
<p>Total Price: <span class="totalPrice"></span></p>
</div>
<div>
<h4>Select a whatsit</h4>
<input type="radio" name="whatsit" value="whatsit1" />Whatsit 1 - $10
<input type="radio" name="whatsit" value="whatsit2" />Whatsit 2 - $22
<h4>Select a whosit</h4>
<input type="radio" name="whosit" value="whosit1" />Whosit 1 - $7
<input type="radio" name="whosit" value="whosit2" />Whosit 2 - $13
jQuery
function updateWhatPrice(){
var whatsitChoice = $("input[name='whatsit']:checked").val();
if(whatsitChoice == "whatsit1"){
$("span.price").text("$10");
}else if(whatsitChoice =="whatsit2"){
$("span.price").text("$22");
}
}
$("input[name='whatsit']").click(function(){
updateWhatPrice();
});
function updateWhoPrice(){
var whositChoice = $("input[name='whosit']:checked").val();
if(whositChoice == "whosit1"){
$("span.whositprice").text("$7");
}else if(whositChoice =="whosit2"){
$("span.whositprice").text("$13");
}
}
$("input[name='whosit']").click(function(){
updateWhoPrice();
});
我想要做的是根据单选按钮的选择更新 totalPrice 跨度。不知道从哪里开始。这是一个jsfiddle:http: //jsfiddle.net/Djd3d/