jQuery로 선택된 값 읽기
$("#select_box option:selected").val();
$("select[name=name]").val();
jQuery로 선택된 내용 읽기
$("#select_box option:selected").text();
선택된 위치
var index = $("#test option").index($("#test option:selected"));
-------------------------------------------------------------------
$("#myselect").append("<option value='1'>Apples</option>");
$("#myselect").append("<option value='2'>After Apples</option>");
// Add options to the start of a select
$("#myselect").prepend("<option value='0'>Before Apples</option>");
// Replace all the options with new options
$("#myselect").html("<option value='1'>Some oranges</option><option value='2'>More Oranges</option><option value='3'>Even more oranges</option>");
// Replace items at a certain index
$("#myselect option:eq(1)").replaceWith("<option value='2'>Some apples</option>");
$("#myselect option:eq(2)").replaceWith("<option value='3'>Some bananas</option>");
// Set the element at index 2 to be selected
$("#myselect option:eq(2)").attr("selected", "selected");
// Set the selected element by text
$("#myselect").val("Some oranges").attr("selected", "selected");
// Set the selected element by value
$("#myselect").val("2");
// Remove an item at a particular index
$("#myselect option:eq(0)").remove();
// Remove first item
$("#myselect option:first").remove();
// Remove last item
$("#myselect option:last").remove();
// Get the text of the selected item
alert($("#myselect option:selected").text());
// Get the value of the selected item
alert($("#myselect option:selected").val());
// Get the index of the selected item
alert($("#myselect option").index($("#myselect option:selected")));
// Alternative way to get the selected item
alert($("#myselect option:selected").prevAll().size());
// Insert an item in after a particular position
$("#myselect option:eq(0)").after("<option value='4'>Some pears</option>");
// Insert an item in before a particular position
$("#myselect option:eq(3)").before("<option value='5'>Some apricots</option>");
// Getting values when item is selected
$("#myselect").change(function() {
alert($(this).val());
alert($(this).children("option:selected").text());
});
댓글 1개
12년 전
좋네요
게시판 목록
프로그램
| 번호 | 제목 | 글쓴이 | 날짜 | 조회 |
|---|---|---|---|---|
| 7930 | 9년 전 | 368 | ||
| 7929 | 9년 전 | 262 | ||
| 7928 | 9년 전 | 371 | ||
| 7927 | 9년 전 | 296 | ||
| 7926 | 9년 전 | 643 | ||
| 7925 | 9년 전 | 311 | ||
| 7924 | 9년 전 | 286 | ||
| 7923 | 9년 전 | 321 | ||
| 7922 | 9년 전 | 341 | ||
| 7921 | 9년 전 | 373 | ||
| 7920 | 9년 전 | 295 | ||
| 7919 | 9년 전 | 311 | ||
| 7918 | 9년 전 | 474 | ||
| 7917 | 9년 전 | 314 | ||
| 7916 | 9년 전 | 382 | ||
| 7915 | 9년 전 | 366 | ||
| 7914 | 9년 전 | 379 | ||
| 7913 | 9년 전 | 504 | ||
| 7912 | 9년 전 | 378 | ||
| 7911 | 9년 전 | 332 | ||
| 7910 | 9년 전 | 359 | ||
| 7909 | 9년 전 | 471 | ||
| 7908 | 9년 전 | 368 | ||
| 7907 | 9년 전 | 319 | ||
| 7906 | 9년 전 | 336 | ||
| 7905 | 9년 전 | 328 | ||
| 7904 | 9년 전 | 295 | ||
| 7903 | 9년 전 | 293 | ||
| 7902 | 9년 전 | 513 | ||
| 7901 |
|
9년 전 | 716 | |
| 7900 | 9년 전 | 538 | ||
| 7899 | 9년 전 | 346 | ||
| 7898 | 9년 전 | 339 | ||
| 7897 | 9년 전 | 296 | ||
| 7896 | 9년 전 | 315 | ||
| 7895 | 9년 전 | 424 | ||
| 7894 | 9년 전 | 346 | ||
| 7893 | 9년 전 | 277 | ||
| 7892 | 9년 전 | 323 | ||
| 7891 | 9년 전 | 709 | ||
| 7890 | 9년 전 | 1174 | ||
| 7889 | 9년 전 | 729 | ||
| 7888 |
limsy1987
|
9년 전 | 527 | |
| 7887 | 9년 전 | 499 | ||
| 7886 | 9년 전 | 388 | ||
| 7885 | 9년 전 | 360 | ||
| 7884 | 9년 전 | 370 | ||
| 7883 | 9년 전 | 349 | ||
| 7882 | 9년 전 | 361 | ||
| 7881 | 9년 전 | 390 | ||
| 7880 | 9년 전 | 516 | ||
| 7879 | 9년 전 | 412 | ||
| 7878 | 9년 전 | 1155 | ||
| 7877 | 9년 전 | 706 | ||
| 7876 | 9년 전 | 434 | ||
| 7875 | 9년 전 | 507 | ||
| 7874 |
|
9년 전 | 779 | |
| 7873 | 9년 전 | 482 | ||
| 7872 | 9년 전 | 615 | ||
| 7871 | 9년 전 | 446 | ||
| 7870 | 9년 전 | 568 | ||
| 7869 | 9년 전 | 385 | ||
| 7868 | 9년 전 | 383 | ||
| 7867 | 9년 전 | 380 | ||
| 7866 | 9년 전 | 440 | ||
| 7865 | 9년 전 | 396 | ||
| 7864 | 9년 전 | 462 | ||
| 7863 | 9년 전 | 452 | ||
| 7862 | 9년 전 | 429 | ||
| 7861 | 9년 전 | 588 | ||
| 7860 | 9년 전 | 594 | ||
| 7859 | 9년 전 | 362 | ||
| 7858 | 9년 전 | 672 | ||
| 7857 | 9년 전 | 1021 | ||
| 7856 | 9년 전 | 483 | ||
| 7855 | 9년 전 | 698 | ||
| 7854 | 9년 전 | 698 | ||
| 7853 | 9년 전 | 538 | ||
| 7852 | 9년 전 | 473 | ||
| 7851 | 9년 전 | 446 | ||
| 7850 | 9년 전 | 541 | ||
| 7849 | 9년 전 | 316 | ||
| 7848 | 9년 전 | 367 | ||
| 7847 | 9년 전 | 587 | ||
| 7846 | 9년 전 | 405 | ||
| 7845 | 9년 전 | 367 | ||
| 7844 | 9년 전 | 365 | ||
| 7843 | 9년 전 | 372 | ||
| 7842 | 9년 전 | 367 | ||
| 7841 | 9년 전 | 354 | ||
| 7840 | 9년 전 | 361 | ||
| 7839 | 9년 전 | 395 | ||
| 7838 | 9년 전 | 479 | ||
| 7837 | 9년 전 | 320 | ||
| 7836 | 9년 전 | 358 | ||
| 7835 | 9년 전 | 440 | ||
| 7834 |
|
9년 전 | 1168 | |
| 7833 | 9년 전 | 374 | ||
| 7832 | 9년 전 | 369 | ||
| 7831 | 9년 전 | 504 |
댓글 작성
댓글을 작성하시려면 로그인이 필요합니다.
로그인하기