私はjqueryで私のselectboxのbird
を選択しようとしています。しかし、それは関係なく、私は何をすべきか、cat
ならないように保持します:jQueryでselect2 selectboxのオプションを選択するにはどうすればよいですか?
$(function() {
$(".select2").select2();
$(".select2").val('bird');
$('.select2').find('option[value="bird"]').prop('selected', true);
});
<link href="https://select2.github.io/dist/css/select2.min.css" rel="stylesheet"/>
<link href="https://select2.github.io/css/bootstrap.css" rel="stylesheet"/>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://select2.github.io/vendor/js/bootstrap.min.js"></script>
<script src="https://select2.github.io/dist/js/select2.full.js"></script>
<div class="form-group">
<select class=" form-control select2" style="width: 100%;">
<option value="cat">Cat</option>
<option value="dog">Dog</option>
<option value="bird">Bird</option>
</select>
</div>
トライ$( 'SELECT2 ')。を見つける(' オプション[値= "鳥"] ')。(、' 選択された' 真)小道具.change() –