datepicker()在我的页面中无法使用jquery

datepicker() not working using jquery in my page

本文关键字:jquery 我的 datepicker      更新时间:2023-09-26

Hi在下面的代码中,datepicker()使用jquery不起作用。但单独来看,它运行良好。

在将代码添加到我的页面后,它就不起作用了——这是我的示例代码。

html

<head>
  <meta charset="utf-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  <title>Admission Form</title>
  <link rel="stylesheet" href="css/admissionform.css">
  <!--[if lt IE 9]><script src="//html5shim.googlecode.com/svn/trunk/html5.js"></script><![endif]-->
<link href="css/bootstrap.css" rel='stylesheet' type='text/css' />
<script src="js/jquery.min.js"></script>
<link href="css/style.css" rel="stylesheet" type="text/css" media="all" />
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="keywords" content="" />

<link href='http://fonts.googleapis.com/css?family=Roboto:400,100,100italic,300,300italic,400italic,500,500italic,700,700italic,900,900italic' rel='stylesheet' type='text/css'>
 <link rel="stylesheet" href="http://code.jquery.com/ui/1.11.4/themes/smoothness/jquery-ui.css">
  <script src="http://code.jquery.com/jquery-1.10.2.js"></script>
  <script src="http://code.jquery.com/ui/1.11.4/jquery-ui.js"></script>
    <script>
  jQuery(document).ready(function() {
  jQuery('.date-picker').datepicker();
});
  </script>   
        <link rel="stylesheet" href="css/flexslider.css">
</head>
<body>
 <p>Date: <input type="text" id="datepicker"></p>
</body>

您有多个对jQuery:的调用

<script src="js/jquery.min.js"></script>
<script src="http://code.jquery.com/jquery-1.10.2.js"></script>

只保留调用(在使用jQuery之前)。同时检查DevTools控制台是否存在其他错误(如果有的话)。

此外,您有<input id="datepicker">,但调用类选择器.date-picker的日期选择器

Input元素带有ID日期选择器,但您已经使用类选择器创建了日期选择器

<input type="text" id="datepicker">
jQuery('.date-picker').datepicker();

使用id选择器

jQuery('#datepicker').datepicker();

检查控制台错误

您使用了2个jquery文件,这也可能导致出现问题