저는 이미 여기에 다른 예제를 보았지만 내 문제는 맞지 않았습니다.jQuery를 사용하여 select 요소의 옵션을 반복합니다.
나는 select
요소를받는 함수가 있는데 JSON 형식의 문자열을 내뱉는 데 필요합니다.
예 :
foo = buildOptionStructure($('.select-test'));
// Returns string of JSON formatted option data from select
// options in element.
function buildOptionStructure(selectElement) {
options = "[";
selectElement.find('option').each(function(option, i) {
console.log(this); // Return my html in console.
console.log(option); // Return a zero based index!
console.log("I VALUE: " + option); // Returns same zero based index!
options += "{";
options += "name:'" + option.text() + "'";
options += "},";
});
options += "]"
return options;
}
난 그냥 주어진 select 요소의 옵션 중 문자열을 구축 할 필요가있다. 내가 여기서 무엇을 놓치고 있니?
. 당신은 또한 당신의 기능에서 아무것도 반환하지 않습니다. –
@ james : 누락 된 견적과 함께 질문을 편집했습니다. – sergserg