【问题标题】:date picker not working in angularjs ng-template script日期选择器在 angularjs ng-template 脚本中不起作用
【发布时间】:2019-09-16 10:53:34
【问题描述】:

我使用了一个弹出窗口来显示一些细节。我需要一个日期选择器,但脚本不起作用。

<div class="container" style="height:auto;">
    <script type="text/ng-template" id="abc.html">
       <div class="input-group date" id="datepicker">
          <input class="form-control"  name="startDate" ng-model="startDate" name="startDate"></input>
          <span class="input-group-addon" >
            <span class="glyphicon glyphicon-calendar"></span>
          </span>
       </div>
    </script>
</div>
<script type="text/javascript">
    $(function() {
        $('#datepicker').datepicker({
              format:"dd-M-yyyy",
              changeMonth: true,
                changeYear: true,
                buttonImage: "images/calendar.gif",
            beforeShowDay: unavailable
        });

    });
</script>

【问题讨论】:

  • 有很多问题。为什么选择器包裹在脚本标签周围。以及为什么 id 是“datepicker1”而您使用的是 $("#datepicker")。而且我认为应该将 datepicker 添加到输入中,而不是 div。
  • 对不起我的错误,id 是 datepicker only

标签: angularjs ng-template


【解决方案1】:

我认为脚本标签中不应该有任何标签。并且应该将 datepicket 添加到输入中。试试这个。

 <div class="container" style="height:auto;">
    <script type="text/ng-template" id="abc.html"></script>
       <div class="input-group date" >
          <input class="form-control" id="datepicker" name="startDate" ng-model="startDate" name="startDate"></input>
          <span class="input-group-addon" >
            <span class="glyphicon glyphicon-calendar"></span>
          </span>
       </div>

</div>
<script type="text/javascript">
    $(function() {
        $('#datepicker').datepicker({
              format:"dd-M-yyyy",
              changeMonth: true,
                changeYear: true,
                buttonImage: "images/calendar.gif",
            beforeShowDay: unavailable
        });

    });
</script>

【讨论】:

  • 代码必须在脚本标签内,否则它不会只显示。另一件事是,如果您在输入标签中提供 id 也不起作用。
猜你喜欢
  • 1970-01-01
  • 2020-08-21
  • 1970-01-01
  • 2018-08-27
  • 1970-01-01
  • 1970-01-01
  • 2019-03-10
  • 2017-03-17
  • 1970-01-01
相关资源
最近更新 更多