W poniższym kodzie, jeśli bieżąca wartość rozwijana wskazuje na wartość dostępną w zmiennej listy , to wybrana wartość menu powinna zostać zmieniona na pierwszą wartość.Resetowanie wartości dropdown do pierwszej wartości przy spełnieniu warunku
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++;
}
}
Próbowałem to:
$("#dk_container_selectForMonth").val($("#dk_container_selectForMonth li:first").val());
ale to nie działa.
Oto 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>
Czy istnieje jakiś sposób, aby to zrobić?
Dodaj również "HTML", aby można było utworzyć fragment roboczy. Trudno debugować to, co tu przedstawiłeś. – sabithpocker
@sabithpocker Proszę znaleźć dodane treści HTML – Kamal