【问题标题】:Datepicker property not applyingDatepicker 属性不适用
【发布时间】:2022-10-24 15:10:02
【问题描述】:

第一组块使用类,第二组块使用 id 但是当使用类时它工作正常但是如果我替换 id 它没有实现

$(".input-monthpicker").datepicker({
        format: "mm-yyyy",
        viewMode: "months",
        minViewMode: "months",
        startDate: new Date(new Date().getFullYear(), '0', '01'),
        autoclose: true
    });

    $("#ForMonth").datepicker({
        format: "mm-yyyy",
        viewMode: "months",
        minViewMode: "months",
        startDate: new Date(new Date().getFullYear(), '0', '01'),
        autoclose: true
    });

剃刀语法

@Html.TextBoxFor(m => m.ForMonth, new { @class = "form-control input-monthpicker validate freezelastyear", placeholder = "Month", @readonly = true, id = "ForMonth" })

请帮帮我

【问题讨论】:

    标签: jquery asp.net-core datepicker


    【解决方案1】:

    这是一个工作演示:

    @Html.TextBoxFor(m => m.ForMonth, new { @class = "form-control input-monthpicker validate freezelastyear", placeholder = "Month", id = "ForMonth" })
    
    @section scripts{
        <link href="https://ajax.googleapis.com/ajax/libs/jqueryui/1.8.1/themes/base/jquery-ui.css" rel="stylesheet" />
        <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
        <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.8.1/jquery-ui.min.js"></script>
      
        <script>
             $("#ForMonth").datepicker({
            format: "mm-yyyy",
            viewMode: "months",
            minViewMode: "months",
            startDate: new Date(new Date().getFullYear(), '0', '01'),
            autoclose: true
        });
        </script>
    }
    

    结果:

    如果它仍然不起作用,请尝试使用:

     $("input[id$=ForMonth]").datepicker({
                format: "mm-yyyy",
                viewMode: "months",
                minViewMode: "months",
                startDate: new Date(new Date().getFullYear(), '0', '01'),
                autoclose: true
            });
    

    【讨论】:

      猜你喜欢
      • 2017-10-30
      • 2010-10-25
      • 1970-01-01
      • 1970-01-01
      • 2018-03-06
      • 2020-08-15
      • 2018-12-12
      • 2012-10-17
      • 1970-01-01
      相关资源
      最近更新 更多