Javascript 满足条件时下拉值重置为第一个值
在下面的代码中,如果当前下拉值指向listvalues变量中可用的值,则下拉选择的值应更改为第一个值Javascript 满足条件时下拉值重置为第一个值,javascript,jquery,css,drop-down-menu,Javascript,Jquery,Css,Drop Down Menu,在下面的代码中,如果当前下拉值指向listvalues变量中可用的值,则下拉选择的值应更改为第一个值 if (selectedForYear() == 2016) { var d = new Date(); var month = d.getMonth(); month = month + 3; while (month <= 13) { $('#dk_container_selectF
if (selectedForYear() == 2016) {
var d = new Date();
var month = d.getMonth();
month = month + 3;
while (month <= 13) {
$('#dk_container_selectForMonth .dk_options li:nth-child(' + month + ')').css({ "display": 'none' });
var listvalues = $('#dk_container_selectForMonth .dk_options li:nth-child(' + month + ')').text();
if ($('#dk_container_selectForMonth .dk_options li.dk_option_current a').text() == listvalues)
{
$("#dk_container_selectForMonth").val($("#dk_container_selectForMonth li:first").val());
}
month++;
}
}
但它不起作用
以下是HTML:
<div class="flexContainer mediumGutter">
<div class="flexContent">
<select data-bind="options: month, optionsCaption: 'Month', value: selectedForMonth" id="selectForMonth" tabindex="8" style="width: 130px">
<option>month</option>
</select>
</div>
<div class="flexContent">
<select data-bind="options: year, optionsCaption: 'Year', value: selectedForYear" id="selectForYear" tabindex="9" style="width: 130px">
<option>year</option>
</select>
</div>
月
年
有办法吗?很抱歉回答我的问题。答案可能对某人有所帮助 通过使用jquery dropkick()方法刷新下拉列表,下拉列表将被刷新并分配第一个值
$('#selectForMonth').dropkick('refresh');
请同时添加
HTML
,以便制作一个工作片段。很难调试您在此处演示的内容。@sabithpocker请查找添加的HTML内容您是否使用自定义选择插件?
$('#selectForMonth').dropkick('refresh');