首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Uncaught:$(.).pickadate不是函数

Uncaught:$(.).pickadate不是函数
EN

Stack Overflow用户
提问于 2018-08-27 17:46:05
回答 1查看 8.8K关注 0票数 2

我目前正在开发一个简单的网络项目。我有一页简单的表格,上面写着他的名字,他的生日,他的大学学位。我使用的是物化和jquery。但这是一场噩梦,因为我无法用这两个人来准确地知道生日。我总是会犯这样的错误:

Uncaught TypeError: $(...).pickadate is not a function

这是我的html:

代码语言:javascript
复制
$(function() {

  $(document).ready(function() {
    $('.datepicker').pickadate({
      selectMonths: true,
      selectYears: 20
    });
    $('select').material_select();
  });
})
代码语言:javascript
复制
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">

<head>
  <meta charset="UTF-8" />
  <link type="text/css" rel="stylesheet" href="/materialize/css/materialize.min.css" media="screen,projection" />
  <link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet" />
  <title>EscolAlura</title>
  <script src="https://code.jquery.com/jquery-2.1.1.min.js"></script>
  <script type="text/javascript" src="/materialize/js/inicializar.js"></script>



</head>

<body class="grey lighten-3">
  <div id="formularioEdicao" class="container">
    <h3 class="main-title center">Cadastrar Aluno</h3>
    <div class="row">
      <form class="col s12" action="#" th:action="@{/aluno/salvar}" th:object="${aluno}" method="post">
        <div class="section">
          <h5>Dados Básicos</h5>
          <div class="row">
            <div class="input-field col s12">
              <input id="nome" type="text" th:field="*{nome}" />
              <label for="nome">Nome</label>
            </div>
          </div>
          <div class="row">
            <div class="input-field col s12">
              <input id="dataNascimento" type="date" class="datepicker" th:field="*{dataNascimento}" />
              <label for="dataNascimento">Dt. Nascimento</label>
            </div>
          </div>
          <div class="row">
            <div class="input-field col s12">
              <input id="curso" type="text" class="validate" th:field="*{curso.nome}" />
              <label for="curso">Curso</label>
            </div>
          </div>

        </div>
        <!-- Fim SECTION Dados Basicos -->

        <div class="row">
          <div class="input-field col s12 center">
            <button class="btn waves-effect waves-light" type="submit" name="action">Salvar Aluno</button>
          </div>
        </div>
      </form>
    </div>

  </div>
  <!-- Fim do formulario de edicao -->
  <script type="text/javascript" src="/materialize/js/materialize.js"></script>
</body>

</html>

我的一页铬纸

有人知道怎么解决这个问题吗?Thx

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2018-08-27 18:12:50

加载脚本的顺序非常重要。

当使用jQuery时,先从它开始,然后加载它。然后是其他插件,然后是定制的JS文件。

见下文

代码语言:javascript
复制
$(document).ready(function() {

    $('.datepicker').pickadate({
        selectMonths: true, 
        selectYears: 20 
      });
      
    $('select').material_select();
});
代码语言:javascript
复制
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/materialize/0.100.2/js/materialize.min.js"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/materialize/0.100.2/css/materialize.min.css" />

<div id="formularioEdicao" class="container">
    <h3 class="main-title center">Cadastrar Aluno</h3>
    <div class="row">
        <form class="col s12" action="#" th:action="@{/aluno/salvar}" th:object="${aluno}" method="post">
            <div class="section">
                <h5>Dados Básicos</h5>
                <div class="row">
                    <div class="input-field col s12">
                        <input id="nome" type="text" th:field="*{nome}" />
                        <label for="nome">Nome</label>
                    </div>
                </div>
                <div class="row">
                    <div class="input-field col s12">
                        <input id="dataNascimento" type="date" class="datepicker" th:field="*{dataNascimento}"/>
                        <label for="dataNascimento">Dt. Nascimento</label>
                    </div>
                </div>
                <div class="row">
                    <div class="input-field col s12">
                        <input id="curso" type="text" class="validate" th:field="*{curso.nome}"  />
                        <label for="curso">Curso</label>
                    </div>
                </div>

            </div> <!-- Fim SECTION Dados Basicos -->

            <div class="row">
                <div class="input-field col s12 center">
                    <button class="btn waves-effect waves-light" type="submit" name="action">Salvar Aluno</button>
                </div>
            </div>
        </form>
    </div>

</div>

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/52044508

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档