Created
October 18, 2013 02:01
-
-
Save springcome/7035363 to your computer and use it in GitHub Desktop.
select, jquery
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<select name="selectName" id="selectId"> | |
<option value="1">1번</option> | |
<option value="2">2번</option> | |
<option value="3">3번</option> | |
</select> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// selected된 값을 알고자 할때 | |
$('#selectId option:selected').val(); | |
// value로 selected하고자 할때 | |
$('#selectId > option[value=1]').attr('selected', true); | |
// selected한 index를 알고자 할때 | |
$('#selectId option').index($('#selectId option:selected')); | |
// index로 value값을 알고자 할때 | |
$('#selectId option:eq(1)').val(); | |
// index로 selected하고자 할때 | |
$('#selectId option:eq(1)').attr('selected', true); | |
// selected한 option삭제 | |
$('#selectId option:selected').remove(); | |
// option 추가 | |
var option = $('<option />').attr('value', 4).html('4번'); | |
$('#selectId').append(option); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment