Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/68.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
选中单选按钮时有关小计算的jquery问题_Jquery_Radio Button - Fatal编程技术网

选中单选按钮时有关小计算的jquery问题

选中单选按钮时有关小计算的jquery问题,jquery,radio-button,Jquery,Radio Button,jQuery HTML: 如何汇总变量,当选中单选按钮并在total cost div中显示时,例如,如果选择了两个单选框,则会出现如下内容:total cost:3$。如果为每次单击创建一个通用的单击处理程序,会比为每次单击创建一个特定的处理程序更容易。给你所有的单选按钮一类的服务或什么的。然后像这样做: <div id="left"> <form> <p>service 1</p><p class="red">Price 1 $&l

jQuery

HTML:


如何汇总变量,当选中单选按钮并在total cost div中显示时,例如,如果选择了两个单选框,则会出现如下内容:total cost:3$。

如果为每次单击创建一个通用的单击处理程序,会比为每次单击创建一个特定的处理程序更容易。给你所有的单选按钮一类的服务或什么的。然后像这样做:

<div id="left">
<form>
<p>service 1</p><p class="red">Price 1 $</p>
Yes<input type="radio" name="service1" value="service1yes" id="service1checked" />
No<input type="radio" name="service1" value="service1no" id="service1no" />


<p>service 2</p><p class="red">Price 2 $</p>
Yes<input type="radio" name="service2" value="service2yes" id="service2checked" />
No<input type="radio" name="service2" value="service2no" id="service2no" />
<br />
<input type="submit">
</form><br />
</div>
<div id="center">

<div class="selecteditems">
Selected Items:
</div>

<div class="totalcost">
Total cost:
</div>

</div>
<div id="left">
<form>
<p>service 1</p><p class="red">Price 1 $</p>
Yes<input type="radio" name="service1" value="service1yes" id="service1checked" />
No<input type="radio" name="service1" value="service1no" id="service1no" />


<p>service 2</p><p class="red">Price 2 $</p>
Yes<input type="radio" name="service2" value="service2yes" id="service2checked" />
No<input type="radio" name="service2" value="service2no" id="service2no" />
<br />
<input type="submit">
</form><br />
</div>
<div id="center">

<div class="selecteditems">
Selected Items:
</div>

<div class="totalcost">
Total cost:
</div>

</div>
var total = 0

$(".services").click( function() {
   recalc()
})

function recalc() {
    if($('#service1checked').checked) {
         $('<div id="service1ok"> Service Number 1, ' //....etc..
         total = total + 1    
    }

    // other conditions ...

    $('#totalcost').html(total)
}