在将复选框的值附加到可编辑的表格中时,我遇到了困难,我在这里有库存...
我正在使用codeigniter ...
Property
选中此复选框时必须自动在其中插入表格
AndroidResourcesFolder
这是我的JavaScript
<div class="col-md-6">
<div class="form-group">
<label for="exampleInputEmail1">Months</label>
<?php foreach ($feetypeList as $feetype) { ?>
<div class="checkbox">
<label style="display: inline-block; max-height: 25px; list-style: none; float: left; padding-top: 5px; width: 130px; margin-right: 40px;">
<input class="chkAdd" type="checkbox" name="feetype_id" value="<?php echo $feetype['id'] ?>" <?php echo set_checkbox('feetype_id', $feetype['id']); ?> ><?php echo $feetype['type'] ?>
</label>
</div>
<?php } ?>
<span class="text-danger"><?php echo form_error('feetype_id'); ?></span>
</div>
输入的信息必须放在我的实际表中
答案 0 :(得分:0)
在这种情况下,当您使用text += $(this).val()+ ',';
时,您的js代码设置了错误的值,this
被引用到当前的click元素,因此您将多次获得相同的值。
使用each
时,需要使用element
而不是this
$('.chkAdd').click(function(){
var text = "";
$('.chkAdd:checked').each(function(index,element){
text += $(element).val()+ ',';
});
text = text.substring(0,text.lenght-1);
$('#tbodyContent').val(text);
});
更新后的答案,如果要填充tbodyContent
的表内容,则$('#tbodyContent').val(text)
无效。您可以使用$('#tbodyContent').html(text)
或$('#tbodyContent').append(text)
,具体取决于值的text
。
text
的值应类似于以下内容:
text='<tr><td>AA</td><td>BB</td></tr>'