jquery select box °ü·ÃµÈ ±â´Éµé
1. jQuery·Î ¼±ÅÃµÈ °ª Àбâ
$("#selectBox option:selected").val();
$("select[name=name]").val();
2. jQuery·Î ¼±ÅÃµÈ ³»¿ë Àбâ
$("#selectBox option:selected").text();
3. ¼±ÅÃµÈ À§Ä¡
var index = $("#test option").index($("#test option:selected"));
4. Addoptions to the end of a select
$("#selectBox").append("<option value='1'>Apples</option>");
$("#selectBox").append("<option value='2'>After Apples</option>");
5. Addoptions to the start of a select
$("#selectBox").prepend("<option value='0'>Before Apples</option>");
6. Replaceall the options with new options
$("#selectBox").html("<option value='1'>Some oranges</option><option value='2'>MoreOranges</option>");
7. Replaceitems at a certain index
$("#selectBox option:eq(1)").replaceWith("<option value='2'>Someapples</option>");
$("#selectBox option:eq(2)").replaceWith("<option value='3'>Somebananas</option>");
8. ÁöÁ¤µÈ index°ªÀ¸·Î select Çϱâ
$("#selectBox option:eq(2)").attr("selected", "selected");
9. text °ªÀ¸·Î select Çϱâ
$("#selectBox").val("Someoranges").attr("selected", "selected");
10. value°ªÀ¸·Î select Çϱâ
$("#selectBox").val("2");
11. ÁöÁ¤µÈ À妽º°ªÀÇ item »èÁ¦
$("#selectBox option:eq(0)").remove();
12. ù¹ø° item »èÁ¦
$("#selectBox option:first").remove();
13. ¸¶Áö¸· item »èÁ¦
$("#selectBox option:last").remove();
14. ¼±ÅÃµÈ ¿É¼ÇÀÇ text ±¸Çϱâ
alert(!$("#selectBox option:selected").text());
15. ¼±ÅÃµÈ ¿É¼ÇÀÇ value ±¸Çϱâ
alert(!$("#selectBox option:selected").val());
16. ¼±ÅÃµÈ ¿É¼Ç index ±¸Çϱâ
alert(!$("#selectBox option").index($("#selectBox option:selected")));
17. SelecBox ¾ÆÀÌÅÛ °¹¼ö ±¸Çϱâ
alert(!$("#selectBox option").size());
18. ¼±ÅÃµÈ ¿É¼Ç ¾ÕÀÇ ¾ÆÀÌÅÛ °¹¼ö
alert(!$("#selectBox option:selected").prevAl!l().size());
19. ¼±ÅÃµÈ ¿É¼Ç ÈÄÀÇ ¾ÆÀÌÅÛ °¹¼ö
alert(!$("#selectBox option:selected").nextAll().size());
20. Insertan item in after a particular position
$("#selectBox option:eq(0)").after("<option value='4'>Somepears</option>");
21. Insertan item in before a particular position
$("#selectBox option:eq(3)").before("<option value='5'>Someapricots</option>");
22. Gettingvalues when item is selected
$("#selectBox").change(function(){
alert(!$(this).val());
alert(!$(this).children("option:selected").text());
});
Ãâó: http://uip80.tistory.com/category/jquery [¿©¸íÀÇÁý]