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개
13년 전
좋네요
게시판 목록
프로그램
| 번호 | 제목 | 글쓴이 | 날짜 | 조회 |
|---|---|---|---|---|
| 230 | 20년 전 | 2089 | ||
| 229 | 20년 전 | 3149 | ||
| 228 | 20년 전 | 3342 | ||
| 227 | 20년 전 | 2417 | ||
| 226 | 20년 전 | 5497 | ||
| 225 | 20년 전 | 2538 | ||
| 224 | 20년 전 | 2981 | ||
| 223 | 20년 전 | 4212 | ||
| 222 | 20년 전 | 2612 | ||
| 221 | 20년 전 | 2302 | ||
| 220 | 20년 전 | 3690 | ||
| 219 | 20년 전 | 2084 | ||
| 218 | 20년 전 | 3587 | ||
| 217 | 20년 전 | 2497 | ||
| 216 | 20년 전 | 2935 | ||
| 215 | 20년 전 | 2245 | ||
| 214 | 20년 전 | 3352 | ||
| 213 | 20년 전 | 2933 | ||
| 212 | 20년 전 | 3073 | ||
| 211 | 20년 전 | 2160 | ||
| 210 | 20년 전 | 1930 | ||
| 209 | 20년 전 | 2383 | ||
| 208 | 20년 전 | 2009 | ||
| 207 | 20년 전 | 1692 | ||
| 206 | 20년 전 | 1866 | ||
| 205 | 20년 전 | 3962 | ||
| 204 | 20년 전 | 1684 | ||
| 203 | 20년 전 | 2025 | ||
| 202 | 20년 전 | 2368 | ||
| 201 | 20년 전 | 1840 | ||
| 200 | 20년 전 | 2972 | ||
| 199 | 20년 전 | 2013 | ||
| 198 | 20년 전 | 2098 | ||
| 197 | 20년 전 | 3669 | ||
| 196 | 20년 전 | 3009 | ||
| 195 | 20년 전 | 2119 | ||
| 194 | 20년 전 | 10273 | ||
| 193 | 20년 전 | 2264 | ||
| 192 | 20년 전 | 1616 | ||
| 191 | 20년 전 | 2680 | ||
| 190 | 20년 전 | 2300 | ||
| 189 | 20년 전 | 1702 | ||
| 188 | 20년 전 | 1504 | ||
| 187 | 20년 전 | 1924 | ||
| 186 | 20년 전 | 1752 | ||
| 185 | 20년 전 | 1796 | ||
| 184 | 20년 전 | 2380 | ||
| 183 | 20년 전 | 1590 | ||
| 182 | 20년 전 | 1498 | ||
| 181 | 20년 전 | 1640 | ||
| 180 | 20년 전 | 2737 | ||
| 179 | 20년 전 | 1825 | ||
| 178 | 20년 전 | 1875 | ||
| 177 | 20년 전 | 2002 | ||
| 176 | 20년 전 | 1812 | ||
| 175 | 20년 전 | 1880 | ||
| 174 | 20년 전 | 1712 | ||
| 173 | 20년 전 | 2071 | ||
| 172 | 20년 전 | 1795 | ||
| 171 | 20년 전 | 2578 | ||
| 170 | 20년 전 | 2298 | ||
| 169 | 20년 전 | 2574 | ||
| 168 | 20년 전 | 1513 | ||
| 167 | 20년 전 | 1599 | ||
| 166 | 20년 전 | 2174 | ||
| 165 | 20년 전 | 1659 | ||
| 164 | 20년 전 | 3792 | ||
| 163 | 20년 전 | 2689 | ||
| 162 | 20년 전 | 2109 | ||
| 161 | 20년 전 | 2819 | ||
| 160 | 20년 전 | 1756 | ||
| 159 | 20년 전 | 1635 | ||
| 158 | 20년 전 | 2587 | ||
| 157 | 20년 전 | 1514 | ||
| 156 | 20년 전 | 1774 | ||
| 155 | 20년 전 | 3249 | ||
| 154 | 20년 전 | 1921 | ||
| 153 | 20년 전 | 1637 | ||
| 152 | 20년 전 | 4974 | ||
| 151 | 20년 전 | 4596 | ||
| 150 | 20년 전 | 3537 | ||
| 149 | 20년 전 | 3816 | ||
| 148 | 20년 전 | 7099 | ||
| 147 | 20년 전 | 3569 | ||
| 146 | 20년 전 | 2647 | ||
| 145 | 20년 전 | 2640 | ||
| 144 | 20년 전 | 7177 | ||
| 143 | 20년 전 | 4623 | ||
| 142 | 20년 전 | 1910 | ||
| 141 | 20년 전 | 3266 | ||
| 140 | 20년 전 | 1986 | ||
| 139 | 20년 전 | 1614 | ||
| 138 | 20년 전 | 2331 | ||
| 137 | 20년 전 | 1805 | ||
| 136 | 20년 전 | 1471 | ||
| 135 | 20년 전 | 1811 | ||
| 134 | 20년 전 | 2989 | ||
| 133 | 20년 전 | 2472 | ||
| 132 | 20년 전 | 1715 | ||
| 131 | 20년 전 | 1666 |
댓글 작성
댓글을 작성하시려면 로그인이 필요합니다.
로그인하기