我有一個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
,我需要的是檢查一個框,只顯示他的電話號碼,然後追加其他地區,在被檢查時, 。