<legend id='Xlzxv'><style id='Xlzxv'><dir id='Xlzxv'><q id='Xlzxv'></q></dir></style></legend>
    <bdo id='Xlzxv'></bdo><ul id='Xlzxv'></ul>
    1. <tfoot id='Xlzxv'></tfoot>

    2. <small id='Xlzxv'></small><noframes id='Xlzxv'>

      <i id='Xlzxv'><tr id='Xlzxv'><dt id='Xlzxv'><q id='Xlzxv'><span id='Xlzxv'><b id='Xlzxv'><form id='Xlzxv'><ins id='Xlzxv'></ins><ul id='Xlzxv'></ul><sub id='Xlzxv'></sub></form><legend id='Xlzxv'></legend><bdo id='Xlzxv'><pre id='Xlzxv'><center id='Xlzxv'></center></pre></bdo></b><th id='Xlzxv'></th></span></q></dt></tr></i><div id='Xlzxv'><tfoot id='Xlzxv'></tfoot><dl id='Xlzxv'><fieldset id='Xlzxv'></fieldset></dl></div>

      添加选中的单选按钮总数

      Adding total of checked Radio Buttons(添加选中的单选按钮总数)

        1. <small id='gWt4m'></small><noframes id='gWt4m'>

        2. <legend id='gWt4m'><style id='gWt4m'><dir id='gWt4m'><q id='gWt4m'></q></dir></style></legend>

          <tfoot id='gWt4m'></tfoot>
            • <bdo id='gWt4m'></bdo><ul id='gWt4m'></ul>
                <tbody id='gWt4m'></tbody>

                <i id='gWt4m'><tr id='gWt4m'><dt id='gWt4m'><q id='gWt4m'><span id='gWt4m'><b id='gWt4m'><form id='gWt4m'><ins id='gWt4m'></ins><ul id='gWt4m'></ul><sub id='gWt4m'></sub></form><legend id='gWt4m'></legend><bdo id='gWt4m'><pre id='gWt4m'><center id='gWt4m'></center></pre></bdo></b><th id='gWt4m'></th></span></q></dt></tr></i><div id='gWt4m'><tfoot id='gWt4m'></tfoot><dl id='gWt4m'><fieldset id='gWt4m'></fieldset></dl></div>
                本文介绍了添加选中的单选按钮总数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                更新

                如果您尝试此链接上的表格 http://jsfiddle.net/Matt_KP/BwmzQ/ 小提琴并选择右上角的 40 英镑单选按钮,然后在底部看到订单总额为 40 英镑.然后,如果您选择 75 英镑,订单总额将变为 75 英镑,但如果您返回并再次检查 40 英镑,则订单总额为 75 英镑 + 40 英镑,而选中的单选按钮应该仅为 40 英镑.

                If you try the form on this link http://jsfiddle.net/Matt_KP/BwmzQ/ the fiddle and select the top right 40 radio button then see the order total at the bottom it says 40. Then if you select the 75 the order total changes to 75 but then if you go back and check the 40 again the order total is 75 + 40 when it should just be 40 for the radio button that is checked.

                更新结束

                我有一个单选按钮部分,如果选择了其他单选按钮,则只能检查某些单选按钮.因此,假设用户选择了一个单选按钮,但随后又选择了另一个单选按钮,则第一个单选按钮将变为未选中状态,因为他们不能同时选择这两个按钮.

                I have a section with Radio buttons where only certain radio buttons can be checked if others are selected. So say if a user selected one Radio Button but then selected another the first Radio Button would become unselected as they cannot have both selected.

                我还在单选按钮中使用了一个名为 data-price 的自定义属性,它保存需要添加的每个单选按钮的值.

                Also I am using a custom attribute in the radio buttons called data-price which holds the value of each radio button that needs to be added toghther.

                问题是当用户选择一个单选按钮时,总数显示正常,但如果用户选择了另一个无法选择前一个单选按钮的单选按钮,它会将总数添加到前一个单选按钮上,它应该只添加单选已选中的按钮.这有点像缓存我认为的总数.

                The problem is when a user selects a Radio Button the total shows fine but then if the user selects another radio button that can't have the previous one selected it adds the total onto the previous one where it should only add the Radio Buttons that are checked. It is kind of like caching the totals I think.

                这是我用来合计选中的单选按钮的:

                This is what I am using to total the checked Radio Buttons:

                <script type="text/javascript">
                jQuery(document).ready(function($){
                $('input:radio').change(function(){
                var total = 0.0;
                $('input:radio:checked').each(function(){
                      total += parseFloat($(this).data('price'));
                });
                $('#total').val(total.toFixed(2));
                });
                
                })
                </script>
                

                推荐答案

                我认为你的大部分问题都可以通过一些新的 HTML 来规避......

                I think the majority of your issues can be circumvented with some new HTML....

                你的 crazy jQuery 代码来限制输入是荒谬的.. 你有名称、价值和你的数据价格属性...分割每个无线电设置项目对我来说似乎有点矫枉过正..

                Your crazy jQuery code to limit the input is ridiculous.. you have name, value, and your data-price attributes... splitting each radio set up by item seems a little overkill to me..

                这是一个有限的示例(根据我们在聊天中的讨论).

                Here is a limited example (as per our discussion in the chat).

                http://jsfiddle.net/CZpnD/ <- 这是您可以使用的示例..

                http://jsfiddle.net/CZpnD/ <- here is the example you can work from..

                要看的主要事情是我如何为每个块"选项使用相同的单选名称,以及当单个选项更改以获得新的总数时我如何循环所有选项(不是最有效的,但它作品).

                the main things to look at are how I used the same radio name for each "block" of options, and how I loop through all options when a single option is changed to get the new total (not the most efficient but it works).

                为了皮特的爱,请使用标签!

                and for the love of pete use labels!

                这篇关于添加选中的单选按钮总数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                相关文档推荐

                keeping radio buttons checked after form submit(表单提交后保持选中单选按钮)
                Styling radio button - not work in IE and Firefox(样式单选按钮 - 在 IE 和 Firefox 中不起作用)
                Toggle HTML radio button by clicking its label(通过单击标签来切换 HTML 单选按钮)
                Javascript how to change radio button label text?(Javascript如何更改单选按钮标签文本?)
                JavaScript radio button confirmation(JavaScript 单选按钮确认)
                How can I automatically select specific radio buttons with Greasemonkey?(如何使用 Greasemonkey 自动选择特定的单选按钮?)
                    <bdo id='EXpnu'></bdo><ul id='EXpnu'></ul>
                      <tbody id='EXpnu'></tbody>
                  • <legend id='EXpnu'><style id='EXpnu'><dir id='EXpnu'><q id='EXpnu'></q></dir></style></legend>

                    1. <small id='EXpnu'></small><noframes id='EXpnu'>

                        <tfoot id='EXpnu'></tfoot>
                      1. <i id='EXpnu'><tr id='EXpnu'><dt id='EXpnu'><q id='EXpnu'><span id='EXpnu'><b id='EXpnu'><form id='EXpnu'><ins id='EXpnu'></ins><ul id='EXpnu'></ul><sub id='EXpnu'></sub></form><legend id='EXpnu'></legend><bdo id='EXpnu'><pre id='EXpnu'><center id='EXpnu'></center></pre></bdo></b><th id='EXpnu'></th></span></q></dt></tr></i><div id='EXpnu'><tfoot id='EXpnu'></tfoot><dl id='EXpnu'><fieldset id='EXpnu'></fieldset></dl></div>