Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/firebase/6.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
Javascript 选中复选框时动态更改选择选项_Javascript_Jquery_Html - Fatal编程技术网

Javascript 选中复选框时动态更改选择选项

Javascript 选中复选框时动态更改选择选项,javascript,jquery,html,Javascript,Jquery,Html,更改单击复选框时的选择选项,我有一个由8个复选框组成的列表,它会动态计数复选框。例如,如果我单击1个复选框,它将显示所选的学分数:1,如果我单击2个复选框,它将显示所选的学分数:2,很快 在复选框下方,我有选择选项,我希望在选中复选框时动态更改选择选项 示例:如果我单击两个复选框,我的选择选项应更改为2 selected,依此类推 有人能帮我实现它吗 谢谢 下面是一个演示示例 HTML <div class="container" > <t

更改单击复选框时的选择选项,我有一个由8个复选框组成的列表,它会动态计数复选框。例如,如果我单击1个复选框,它将显示所选的学分数:1,如果我单击2个复选框,它将显示所选的学分数:2,很快

在复选框下方,我有选择选项,我希望在选中复选框时动态更改选择选项 示例:如果我单击两个复选框,我的选择选项应更改为2 selected,依此类推

有人能帮我实现它吗

谢谢

下面是一个演示示例

HTML

   <div class="container" >
                <table class="table table-striped">
                    <tr>
                        <td align="center">
                            <div class="checkbox">
                                <label>
                                    <input type="checkbox" value="1" class="no_of_credits">
                                </label>
                            </div>
                        </td>
                        <td align="center">
                            <div class="checkbox">
                                <label>
                                    <input type="checkbox" value="1" class="no_of_credits">
                                </label>
                            </div>
                        </td>
                        <td align="center">
                            <div class="checkbox">
                                <label>
                                    <input type="checkbox" value="1" class="no_of_credits">
                                </label>
                            </div>
                        </td>
                        <td align="center">
                            <div class="checkbox">
                                <label>
                                    <input type="checkbox" value="1" class="no_of_credits">
                                </label>
                            </div>
                        </td>
                        <td align="center">
                            <div class="checkbox">
                                <label>
                                    <input type="checkbox" value="1" class="no_of_credits">
                                </label>
                            </div>
                        </td>
                        <td align="center">
                            <div class="checkbox">
                                <label>
                                    <input type="checkbox" value="1" class="no_of_credits">
                                </label>
                            </div>
                        </td>
                        <td align="center">
                            <div class="checkbox">
                                <label>
                                    <input type="checkbox" value="1" class="no_of_credits">
                                </label>
                            </div>
                        </td>
                        <td align="center">
                            <div class="checkbox">
                                <label>
                                    <input type="checkbox" value="1" class="no_of_credits">
                                </label>
                            </div>
                        </td>
                        <td align="center">
                            <div class="checkbox">
                                <label>
                                    <input type="checkbox" value="1" class="no_of_credits">
                                </label>
                            </div>
                        </td>
                        <td align="center">
                            <div class="checkbox">
                                <label>
                                    <input type="checkbox" value="1" class="no_of_credits">
                                </label>
                            </div>
                        </td>
                        <td align="center">
                            <div class="checkbox">
                                <label>
                                    <input type="checkbox" value="1" class="no_of_credits">
                                </label>
                            </div>
                        </td>
                        <td align="center">
                            <div class="checkbox">
                                <label>
                                    <input type="checkbox" value="1" class="no_of_credits">
                                </label>
                            </div>
                        </td>
                    </tr>
                </table>
            </div>
            <div class="container">
                <div class="row">
                    <div class="text-center">
                        <h1  class="print_no_of_credits">Number Of Credits Selected : 0</h1>

                    </div>
                </div>
            </div>
        </div>

    <form class="form-group">
                <select class="form-control">
                    <option value="1 selected">1 selected</option>
                    <option value="2 selected">2 selected</option>
                    <option value="3 selected">3 selected</option>
                    <option value="4 selected">4 selected</option>
                    <option value="5 selected">5 selected</option>
                    <option value="6 selected">6 selected</option>
                    <option value="7 selected">7 selected</option>
                    <option value="8 selected">8 selected</option>
                    <option value="9 selected">9 selected</option>
                    <option value="10 selected">10 selected</option>
                    <option value="11 selected">11 selected</option>
                    <option value="12 selected">12 selected</option>
                </select> 
        </form>

所选学分数:0
选定1个
2选定
选定的3个
选定的4个
选定的5个
选定的6个
选出7名
8选定
9选定
选出10名
11名获选
选定的12个
JQUERY

$(document).ready(function()
        {
            $('input[type="checkbox"]').click(function()
            {
                var total = ($('.no_of_credits:checked').length)+0;
                $(".print_no_of_credits").html( "<h1>Number Of Credits Selected : "+total+"</h1>" ).length;
            });

        });
$(文档).ready(函数()
{
$('input[type=“checkbox”]”)。单击(函数()
{
风险价值总额=($('.信用额度的数量:已检查')。长度)+0;
$(“.print_no_of_credits”).html(“所选信用数:“+total+”).length;
});
});

只需将下面的行添加到您的
单击事件中

$('.form-control').val(total + " selected");
因此,您的更新代码将是:

$('input[type="checkbox"]').click(function() {
    var total = ($('.no_of_credits:checked').length) + 0;
    $(".print_no_of_credits").html("<h1>Number Of Credits Selected : " + total + "</h1>").length;
    $('.form-control').val(total + " selected");
});

只需将下面的行添加到您的
单击事件中

$('.form-control').val(total + " selected");
因此,您的更新代码将是:

$('input[type="checkbox"]').click(function() {
    var total = ($('.no_of_credits:checked').length) + 0;
    $(".print_no_of_credits").html("<h1>Number Of Credits Selected : " + total + "</h1>").length;
    $('.form-control').val(total + " selected");
});

谢谢@Guruprasad.随时。。快乐编码…)谢谢@Guruprasad.随时。。快乐编码…)