如何添加复选框名称? [英] How to append the checked boxes name?
问题描述
在此小提琴
有一个
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屋!