如何从更改函数中的jquery datepicker获取月份和年份值

时间:2017-09-18 09:58:15

标签: jquery

任何人都可以告诉我如何在onchange函数中获取月份和年份值并且不使用.datepicker({

即使更改函数没有调用我如何从下拉列表中获取值 HTML: -



<div class="dpicker" id="mnthyear"><input type="text" maxlength="10" id="SCAactionmonth" class="form-control formdatepicker"  aria-label="What month would you like this SCA action to be presented to the Service Contract Approval Review Board (SCARB)?" /></div>
&#13;
&#13;
&#13;

&#13;
&#13;
 $(document).on('change',".ui-datepicker-year",function (e) {
        var year=$(".ui-datepicker-year option:selected").text(); 
        $("#SCAactionmonth").text(year);
    }) 
&#13;
&#13;
&#13;

1 个答案:

答案 0 :(得分:0)

删除$("#stopAlarm").click(function(){ $("#tableContainer").removeClass("blink"); }); 。您正在使用datepicker,因此它适用于输入  输入文字。

&#13;
&#13;
option:selected
&#13;
$('#datepicker').datepicker();
$(document).on('change', ".ui-datepicker-year", function(e) {
  var year = $(".ui-datepicker-year").text();
  $("#SCAactionmonth").text(year);
});
&#13;
&#13;
&#13;

但我建议使用datepicker更改。

&#13;
&#13;
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.0/jquery.min.js"></script>
<script src="https://code.jquery.com/ui/1.11.4/jquery-ui.min.js"></script>
<input id="datepicker" type="datepicker" class='ui-datepicker-year' name="date" placeholder="Date" />

<label id='SCAactionmonth'></label>
&#13;
$('#datepicker').datepicker()
    .on("change", function (e) {
        $('#SCAactionmonth').text($(this).val())
        
});
&#13;
&#13;
&#13;