이 해결책에 대한 간단한 대답이 있기 전에 이미 또는 이미 질문되었을 수 있지만 현재 멈추었습니다. 이 양식은 http://jsfiddle.net/DS73u/에서 볼 수 있습니다. 사용자는 고유 한 이름으로 3 가지 다른 방법으로 좌표를 입력 할 수 있습니다. 사용자가 양식에 입력을 추가 할 수 있도록 둘 이상의 입구가있을 수도 있습니다. 나는 체크 된 모든 체크 박스 입력을 반복하고 배열 2D 배열에 값을 저장합니다. 그것이 어떤 계획을 저장하고 좌표 값을 저장하는지. 따라서 사용자는 배열에 저장되는 55.67484와 -86.7685를 입력하고 temp [0] = 55.67484 AND temp [0] [1] = -86.7685로 액세스 할 수 있습니다.jquery를 사용하여 루프에서 onchange를 감지하는 방법
그 후에는 입구를 기준으로 각 좌표 그룹을 구분하고 싶습니다. 나는 개체 배열에 2D 배열을 저장합니다. 여기서 ent_name은 속성 이름입니다. 입구 이름을 기준으로 값을 나누는 데 문제가 있지만 모든 값이 루프 내에 포함되어 있기 때문에이를 비교하는 방법을 모르겠습니다. 어쩌면 onchange() 또는 change()가 jquery에서 작동할까요? 질문 가장, 어디 당신의 정보를 저장하는 방법에 대해 당신이있는 것처럼 텍스트 필드의 값은 지금까지
$(function() {
/*
This is where the magic happens when you click
the "Preview Map" button
It does several things...
1.Loops through every checkbox in the #entrances
2.Check to see if Entrance name has changed and store it into object with array of coordinates
2.Checks to see if the checkbox is checked
a.Yes
1.We see what checkbox is being checked
to determine how we want to output the data
inputted(Hence the switch)
2.We grab the data from the form and store it
into an array called coordinates
b.No
1.Do nothing
*/
$('#prev_map').click(function() {
//Make sure coordinates is empty before proceeding
coordinates = {};
temp = [];
var ent_name;
//console.log($('#entrances input:checkbox'));
$('#entrances input:checkbox').each(function(){
if (this.checked) {
//console.log($(this).parent('#coords').prevAll('input').val());
//coordinates.push($(this).parent('#coords').prevAll('input').val());
ent_name = $(this).parent('#coords').prevAll('input').map(function() {
console.log(ent_name);
}).get().change(function() {
console.log("We changed");
});
/*
ent_name = $(this).parent('#coords').prevAll('input').map(function() {
return $(this).val();
}).get();
console.log("Entrance Name: " + ent_name);
if (temp_name != ent_name) {
coordinates[temp_name] = temp;
} else {
temp = [];
};
var temp_name = ent_name;
console.log("Temporary Name: " + temp_name);*/
switch(this.name) {
case "dec_coord":
temp.push($(this,'input').next().children('input').map(function() {
return $(this).val();
}).get());
break;
case "deg_coord":
var temp2 = $(this,'input').next().children("input,select").map(function() {
return $(this).val();
}).get().join(";");
//console.log(temp);
temp2 = temp2.toString();
temp2 = temp2.replace(";","°");
temp2 = temp2.replace(";","'");
temp2 = temp2.replace(";","\"");
temp2 = temp2.replace(";",",");
temp2 = temp2.replace(";","°");
temp2 = temp2.replace(";","'");
temp2 = temp2.replace(";","\"");
temp.push(temp2.split(","));
break;
case "utm_coord":
temp.push($(this,'input').next().children('input,select').map(function() {
return $(this).val();
}).get().join(","));
break;
}
} else {
//console.log("wrong");
};
});
$('#dialog').dialog({
width: 500,
height: 400,
open: function() {
//loadMap();
}
});
});
/*
This is the replication of the Entrance Fields
We will limit the number of entrances to 5
*/
var template = $('#entrances .ent_clone:first').clone();
var cloneCount = 0;
var addEntrance = function(){
cloneCount++;
var entrance = template.clone().find(':input').each(function() {
var newID = this.id+cloneCount;
//$(this).prev().attr('for', newID);
this.id = newID;
}).end()
.attr('id', 'ent' + cloneCount)
.appendTo("#ent");
};
$('#addEnt').click(addEntrance);
});
문제를 해결 한 경우 자신의 질문에 대한 답변을 게시 한 다음 대답을 수락 할 수 있습니다. 이것은 공식적으로 질문을 "닫고"다른 사람들을 도울 것이므로이 문제에 대한 해결책이 있음을 알게 될 것입니다. – JasCav