옵션을 동적으로 선택하려면 (한 줄씩 텍스트 영역에서 가져옵니다). 그러나 다음 스 니펫은 항목을 두 번 추가합니다. 내가 결함이있는 곳? 팁 주셔서 감사합니다.jQuery each - 메서드를 두 번 추가합니다.
function changeOptions() {
var lines = [];
$('#simulation').empty();
var lines = $('textarea').val().split('\n');
console.log ('lines.length ', lines.length);
for (var i = 0; i < lines.length; i++) {
$.each(lines, function(i, lines) {
$('#simulation').append($('<option>', {
value : lines,
text : lines
}));
});
}
};
왜'for' 루프 안에'.each()'가 들어 있습니까? –
안녕하세요. $ .each를 사용하지 않으면 항목을 줄 단위로 가져 오지 않습니다. – mm1975