<select id="mySelect2"> <option value="1">选项1</option> <option value="2">选项2</option> <option value="3">选项3</option> </select> 在JavaScript中,使用$('#mySelect2').val()来获取选中项的值。 代码语言:txt 复制 var selectedValues = $('#mySelect2').val(); ...
如果您使用 不带AJAX 的 select2, 您可以执行以下操作: <select name="mySelect2" id="mySelect2"> <option value="0">One</option> <option value="1">Two</option> <option value="2">Three</option> </select> /* "One" will be the selected option */ $('[name=mySelect2]').val("0...
$('#language').select2(); <select id="language" class="form-control" multiple="multiple" data-toggle="select2"> <option value="1">FR</option> <option value="1">Eng</option> <option value="1">Es</option> </select> var selectedValues = $('#language').val(); console.log(select...
<select id="select_four" multiple="multiple" size=3 style="height: 200px;width:100px"></select> <select id="select_five" multiple="multiple" style="height: 200px;width: 100px;"> <option value="0" selected="selected">百度</option> <option value="1" selected="selected">腾讯</option...
<option value="100" selected="selected">默认项</option> </select> </body> <script> $(document).ready(function(){ $("#select2_sample").select2({ ajax: { url : "http://123.57.28.146:8088/sample",//请求的API地址 dataType: 'json',//数据类型 ...
$("#id_select2_demo1").prop('disabled',true);$("#id_select2_demo4").prop('disabled',true);动态添加 select 的 option $('#add').click(function() { var _html = '<option value="9" selected>select2.github.io/select2/</option>'; $('#id_select2_demo1').append(_html)....
var selectedValues = $('#select2-field').val(); 根据选择的值来显示/隐藏div。可以使用each()方法遍历选择的值,并根据每个值的条件来显示或隐藏相应的div。 代码语言:txt 复制 $.each(selectedValues, function(index, value) { if (value === 'value1') { $('#div1').show(); } e...
// 选中value为"option2"的选项$("select option[value='option2']").prop("selected",true); 1. 2. 动态设置select选项 除了设置选项的值,我们还可以动态地添加和删除选项。 1. 添加选项 要添加选项,我们可以使用.append()方法或.html()方法。
1. $("#select_id ").get(0).selectedIndex=1; //设置Select索引值为1的项选中2. $("#select_id ").val(4); //设置Select的Value值为4的项选中3. $("#select_id option[text='jQuery']").attr("selected", true); //设置Select的Text值为jQuery的项选中 jQuery添加/删除Select的Option项: ...
1、jquery获取当前选中select的text值 var checkText=$("#slc1").find("option:selected").text(); 2、jquery获取当前选中select的value值 var checkValue=$("#slc1").val(); 3、jquery获取当前选中select的索引值 var index=$("#slc1 ").get(0).selectedIndex; ...