lottogame
홈
태그
미디어로그
위치로그
방명록
Programing
반복
lottogame
2020. 5. 16. 10:01
반응형
반복
옵션 HTML에 <select> 요소가 있습니다.
이 요소는 드롭 다운 목록을 나타냅니다.
JQuery를 통해 <select> 요소의 옵션을 반복하는 방법을 이해하려고합니다.
JQuery를 사용하여 <select> 요소에 각 옵션의 값과 텍스트를 표시하려면 어떻게합니까?
그냥 alert () 상자에 표시하고 싶습니다.
$ ( "# selectId> option"). each (function () {alert (this.text + ''+ this.value);});
http://api.jquery.com/each/ http://jsfiddle.net/Rx3AP/ 이것은 나를 위해 일했다 $ (function () {$ ( "# select option"). each (function (i) {alert ( $ (this) .text () + ":"+ $ (this) .val ());});});
각각 인덱스와 요소에 매개 변수화 된 매개 변수를 사용할 수도 있습니다.
$ ( '# selectIntegrationConf'). find ( 'option'). each (function (index, element) {console.log (index);
console.log (element.value);
console.log (element.text);
});
// $ ( '# selectIntegrationConf option'). each (function (index, element) {console.log (index); console.log (element.value); console.log (element.text);}에서도 작동합니다. );
구글이 여기에 모든 사람을 보내는 것처럼 보이기 때문에 추종자에게 필요한 비 jquery 방식입니다. var select = document.getElementById ( "select_id");
for (var i = 0; i <select.length; i ++) {var option = select.options [i];
// 이제 option.text, option.value가 있습니다.}이 방법도 시도해 볼 수 있습니다.
HTML 코드 <select id = "mySelectionBox"> <option value = "hello"> Foo </ option> <option value = "hello1"> Foo1 </ option> <option value = "hello2"> Foo2 </ option> <option value = "hello3"> Foo3 <
/ option> </ select> 당신은 JQuery 코드 $ ( "# mySelectionBox 옵션") .each (function () {alert (this.text + ''+ this.value);});
또는 var select = $ ( '# mySelectionBox') [0];
for (var i = 0; i <select.length; i ++) {var option = select.options [i];
경고 (option.text + ''+ option.value);
} $ .each ($ ( "# MySelect 옵션"), function () {alert ($ (this) .text () + "-"+ $ (this) .val ());});
(document.getElementById ( 'mySelect')의 const 옵션)에 대해 Jquery를 원하지 않고 ES6을 사용할 수있는 경우 {console.log (option);
} 참고 URL : https://stackoverflow.com/questions/2950152/iterate-through-select-options
each (function () {alert (this.text + ''+ this.value);});
또는 var select = $ ( '# mySelectionBox') [0];
for (var i = 0; i <select.length; i ++) {var option = select.options [i];
경고 (option.text + ''+ option.value);
} $ .each ($ ( "# MySelect 옵션"), function () {alert ($ (this) .text () + "-"+ $ (this) .val ());});
(document.getElementById ( 'mySelect')의 const 옵션)에 대해 Jquery를 원하지 않고 ES6을 사용할 수있는 경우 {console.log (option);
} 참고 URL : https://stackoverflow.com/questions/2950152/iterate-through-select-options
each (function () {alert (this.text + ''+ this.value);});
또는 var select = $ ( '# mySelectionBox') [0];
for (var i = 0; i <select.length; i ++) {var option = select.options [i];
경고 (option.text + ''+ option.value);
} $ .each ($ ( "# MySelect 옵션"), function () {alert ($ (this) .text () + "-"+ $ (this) .val ());});
(document.getElementById ( 'mySelect')의 const 옵션)에 대해 Jquery를 원하지 않고 ES6을 사용할 수있는 경우 {console.log (option);
} 참고 URL : https://stackoverflow.com/questions/2950152/iterate-through-select-options
텍스트 + ''+ option.value);
} $ .each ($ ( "# MySelect 옵션"), function () {alert ($ (this) .text () + "-"+ $ (this) .val ());});
(document.getElementById ( 'mySelect')의 const 옵션)에 대해 Jquery를 원하지 않고 ES6을 사용할 수있는 경우 {console.log (option);
} 참고 URL : https://stackoverflow.com/questions/2950152/iterate-through-select-options
텍스트 + ''+ option.value);
} $ .each ($ ( "# MySelect 옵션"), function () {alert ($ (this) .text () + "-"+ $ (this) .val ());});
(document.getElementById ( 'mySelect')의 const 옵션)에 대해 Jquery를 원하지 않고 ES6을 사용할 수있는 경우 {console.log (option);
} 참고 URL : https://stackoverflow.com/questions/2950152/iterate-through-select-options
반응형
공유하기
게시글 관리
lottogame
'
Programing
' 카테고리의 다른 글
Android API 21 툴바 패딩
(0)
2020.05.16
ASP.NET Core의 .json 파일에서 AppSettings 값을 읽는 방법
(0)
2020.05.16
bash에 대한 별칭의 여러 명령
(0)
2020.05.16
Xcode 5에서 사용할 수있는 새로운 설명서 명령은 무엇입니까?
(0)
2020.05.16
열에서 고유 한 값 선택
(0)
2020.05.16
티스토리툴바