【问题标题】:jQuery UI datepicker doesn't not open/appear on click:jQuery UI datepicker 不会在点击时打开/出现:
【发布时间】:2016-07-19 16:18:19
【问题描述】:
<script src="https://code.jquery.com/jquery-1.10.2.js"></script>
<script src="https://code.jquery.com/ui/1.11.2/jquery-ui.js"></script>
<script src="~/wwwroot/js/datePicker.js"></script>

datePicker.js:

 (function ($) {
   $("#datepicker").datepicker();
 })(jQuery);

html:

 <td>
    <input type="text" id="datepicker">
 </td>

css:

   <link rel="stylesheet" href="https://code.jquery.com/ui/1.11.2/themes/smoothness/jquery-ui.css">

我不明白为什么单击文本输入字段时日历没有打开。我究竟做错了什么?奇怪的是,当我将这些元素隔离在一个带有内联脚本的小 html 中时,它似乎可以工作。

编辑:完整的html

@section Scripts {
    <script src="https://code.jquery.com/jquery-1.10.2.js"></script>
    <script src="https://code.jquery.com/ui/1.11.2/jquery-ui.js"></script>
    <script src="~/wwwroot/js/angular/angular.min.js"></script>
    <script src="~/wwwroot/js/angular/angular-route.min.js"></script>
    <script src="~/wwwroot/js/simpleControls.js"></script>
    <script src="~/wwwroot/js/MassScheduler/schedulerLayout.js"></script>
    <script src="~/wwwroot/js/MassScheduler/massScheduler.js"></script>
    <script src="~/wwwroot/js/MassScheduler/schedulerManager.js"></script>
    <script src="./wwwroot/js/MassScheduler/schedulerController.js"></script>
    <script src="~/wwwroot/js/MassScheduler/schedulerTableFilter.js"></script>
    <script></script>
}

<div class="container-fluid">
    <div class="row" ng-app="massScheduler">
        <div ng-view></div>
    </div>
</div>

ng-视图:

<div ng-controller="schedulerController as vm">
    <div id="scheduler-index-main">
        <scheduler-form ng-show="!vm.showErrorMessage"></scheduler-form>
        <scheduler-status-table ng-show="!vm.showErrorMessage"></scheduler-status-table>
        <div ng-show="vm.showErrorMessage" id="error-message">
            <h4>Error occurred. Please try again later.</h4>
        </div>
    </div>
</div>

没有错误输出到控制台。我替换了 datePicker.js 的路径。它正在查找文件,我可以在 Chrome 工具中看到它。但是输入没有显示。

【问题讨论】:

  • 很难说,从您发布的内容来看,应该可以正常工作。您的整个页面上一定还有其他内容导致您的问题jsfiddle.net/ygfdzekd
  • 一定是路径问题。检查你的控制台,并发布错误!
  • @Iceman 在控制台中没有报告错误。我想知道这是否也是使用 Angular 路由的问题?
  • @JohnDoe 用绝对路径替换~/wwwroot/js/datePicker.js
  • 你为什么要结合jQuery angular? Angular 对日期选择器有很多很好的指令。例如这里是 Angular 引导程序。 angular-ui.github.io/bootstrap

标签: jquery angularjs datepicker


【解决方案1】:

您的代码正在运行,请检查您的 js 路径是否正常(“~/wwwroot/js/datePicker.js”)。

 (function ($) {
   $("#datepicker").datepicker();
 })(jQuery);
<script src="https://code.jquery.com/jquery-1.10.2.js"></script>
<script src="https://code.jquery.com/ui/1.11.2/jquery-ui.js"></script>
   <link rel="stylesheet" href="https://code.jquery.com/ui/1.11.2/themes/smoothness/jquery-ui.css">
<td>
    <input type="text" id="datepicker">
 </td>

【讨论】:

  • 这不是真正的“答案”,应该是评论。但是您是正确的,因为发布的代码没有任何问题。您建议的其他可能路径导致了问题。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-08-06
  • 2015-04-13
  • 2015-06-08
  • 2023-03-26
相关资源
最近更新 更多