如何添加复选框名称? [英] How to append the checked boxes name?

查看:144
本文介绍了如何添加复选框名称?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在此小提琴 有一个和当其按一个模式对话框appears.The对话框有一个下拉menu.When 下拉选择,然后用复选框表appear.Please告诉我如何选中复选框时附加复选框名称,或者取消选中复选框则删除删除附加名称.

In this fiddle There is a To and when its pressed a modal dialog box appears.The dialog box has a drop down menu.When groups or users drop down is selected then a table with check boxes appear.Please tell me how to append the check boxes name when check boxes are selected or delete the delete the appended names when the check box is unselected.

要附加我必须喜欢

$('#ToAdd').append('hi');

但是我不知道如何调用它并获取值.请帮助

But I dont know how to call this and get the values.please help

示例

假设已选择"groups"菜单,并从以下复选框中选择了第一行,则hhh将显示在跨度中

Suppose groups menu is selected and from the below check boxes,1st row is selected Then hhh will be displayed in the span

<span id="ToAdd"></span>

推荐答案

首先,我将两个表#mytable#groupTable移至对话框

First, I moved the two tables #mytable and #groupTable to the dialog

<div class="tab-content ">
    <div class="tab-pane " id="users">Users
        <table id="mytable" class="table table-bordered">
...
        </table>
    </div>
    <div class="tab-pane" id="groups">Groups
        <table id="groupsTable" class="table table-bordered">
...
        </table>
    </div>
</div>

这简化了两个标签之间的切换

This simplifies switching between the two tabs

$('.select').on('change', function () {
    var tablink = '#' + $(this).val();
    $('a[href="' + tablink + '"]').tab('show');
});

现在,您可以轻松获取选中的姓名

Now, you can easily pick up the checked names

function collect_users() {
    var users = [];
    $('input:checked', '#mytable').closest('td').next('td').each(function() {
        users.push($(this).text());
    });

    $('#ToAdd').text(users.join(', '));
}

$('#mytable input:checkbox').click(collect_users);

#groupTable类似.

请参阅修改后的 JSFiddle

这篇关于如何添加复选框名称?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆