【问题标题】:JQuery Datepicker not displaying or workingJQuery Datepicker不显示或工作
【发布时间】:2017-12-21 18:21:14
【问题描述】:

我正在尝试在联系表单中包含一个 jquery datepicker。

不幸的是,由于未知原因它无法正常工作(它正在同一站点上的其他表单中工作)

有人可以帮助澄清为什么它不起作用吗?它现在只是充当一个文本框,没有任何弹出窗口:

请注意:表格存储在卡片中,不确定这是否会影响它,但我听说表格和卡片不能很好地混合

脚本:

 <link rel="stylesheet" 
 href="//code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css">
 <link rel="stylesheet" href="/resources/demos/style.css">
 <script src="https://code.jquery.com/jquery-1.12.4.js"></script>
 <script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js">
 </script>
 <script>
    $( function() {
          $( "#datepicker" ).datepicker({
              dateFormat: "yy-mm-dd"
          });
      } );
 </script>

 <div class="form-group">
     <label for="datepicker">Pick a date</label>
     <input type="text" date-date-format="yy-mm-dd" name="datepicker" 
     id="datepicker" class="form-control">
 </div>

控制台返回:

Uncaught TypeError: $(...).datepicker is not a function at HTML 文档。 (index.php:20) 着火 (jquery-1.12.4.js:3232) 在 Object.fireWith [as resolveWith] (jquery-1.12.4.js:3362) 在 Function.ready (jquery-1.12.4.js:3582) 在 HTMLDocument.completed (jquery-1.12.4.js:3617)

【问题讨论】:

  • 您确定这是标记中唯一具有该 id 的元素吗?
  • 控制台有没有说什么?
  • 实际上并没有考虑检查控制台。它说:Uncaught TypeError: $(...).datepicker is not a function at HTMLDocument. (index.php:20) at fire (jquery-1.12.4.js:3232) at Object.fireWith [as resolveWith] (jquery-1.12.4.js:3362) 在 Function.ready (jquery-1.12.4.js:3582) 在 HTMLDocument.completed (jquery-1.12.4.js:3617)
  • 嗨亚当,是的,这是唯一具有日期选择器 ID 的元素

标签: php jquery html jquery-ui-datepicker


【解决方案1】:

发现问题。 看来我在页面底部有一个我认为是不相关的脚本,两者发生冲突并导致错误

【讨论】:

  • 啊,这样就行了!很高兴你找到了答案。
【解决方案2】:

我建议使用 Google CDN,而不是 jQuery 的服务器。 由于您使用的是 php,因此您可能需要将 type="text/javascript" 添加到您的脚本标签中,看看这是否会有所不同。

<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
</head>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-02-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多