我有一个jQuery
脚本,它将所有复选框值附加到','
中的一个<input type="text"/>
中,但是当选中一个框时,它会同时附加其他复选框的所有值,而且我只需要以附加依次检查的那些。从复选框中的输入文本中逐个追加
$('.check_list').on('change', function() {
var n = $(this).siblings('input:checkbox');
var nControl = $('.codeParc');
if ($(this).prop('checked')) {
n.prop('checked', true);
var vals = nControl.map(function() {
return $(this).val();
}).get().join(',');
} else {
n.prop('checked', false);
}
$('#test').val(vals);
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<input style="cursor: pointer;" type="checkbox" value="" class="check_list"></input>
<input type="checkbox" class="codeParc" value="1"></input>
<input type="checkbox" class="codeParc" value="2"></input>
<input type="checkbox" class="codeParc" value="3"></input>
<input type="text" id="test" value=""></input>
此代码返回我,每当我选中一个复选框所有值1,2,3
,我需要的是检查一个框,只显示他的电话号码,然后追加其他地区,在被检查时, 。