【问题标题】:Bootstrap datepicker calendar not displaying for the below code引导日期选择器日历未显示以下代码
【发布时间】:2015-12-25 14:52:33
【问题描述】:

我无法在以下代码中显示用于预约的日历。任何人都可以帮助我获得正确的解决方案。不确定 datepicker 的脚本是否应该包含在 php 中或外部。

  <!doctype html>
  <html>
  <head>
      <meta charset="utf-8">
      <title>abc</title>
      <link rel="stylesheet" href="css/justdental_style.css">
      <link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css" rel="stylesheet">
      <link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap-theme.min.css" rel="stylesheet">
      <link href="https://raw.githubusercontent.com/Eonasdan/bootstrap-datetimepicker/master/build/css/bootstrap-datetimepicker.min.css" rel="stylesheet">
  </head>

  <?php
  include_once("connection.php");

  $sql = "SELECT FIRST_NAME,QUALIFICATION,Specialization,LAST_NAME,   
  Adress1, Consultation_Fee, Experience, Adress2 from t_doctorprofile";
  $results = mysqli_query($db,$sql) or die('Error in connection');

  echo '<h3 style="color:purple"><strong>Available Dentists</strong></h3>';

  while($result = mysqli_fetch_assoc($results)){
      echo '<div class="fetch">';

      echo "<p>".$result['FIRST_NAME']." ".$result['LAST_NAME']."</p>";

      echo "<p>".$result['QUALIFICATION']."</p>";
      echo "<p>".$result['Specialization']."</p>";
      echo "<p>".$result['Adress1']." ".$result['Adress2']."</p>";
      echo "<p>"."<b>Consultation Fee-</b>"." ".$result['Consultation_Fee']."</p>";
      echo "<p>"."<b>Experience-</b>"." ".$result['Experience']."years"."</p>";

      echo "<div class='container'>";
      echo "<div class='row'>";
      echo "<div class='col-sm-2' style='margin-left:130px;margin-top:120px;'>";
      echo   "<div class='form-group'>";
      echo  "<div class='input-group date' id='datetimepicker5'>";
      echo   "<input type='text' class='form-control' />";
      echo "<span class='input-group-addon'>";
      echo "<span class='glyphicon glyphicon-calendar'>";
      echo "</span>";

      echo "</div>";
      echo "</div>";
      echo "</div>";

      echo '</div>';
      echo '</div>';
      echo '</div>';

  } 
  ?>     

 <script type="text/javascript">
    $(function () {
        $('#datetimepicker5').datetimepicker();
    });
 </script>

【问题讨论】:

  • 这不是完整的代码。我看到了 PHP 的结束标记,但没有看到开始标记。请全部发布。
  • echo '&lt;div class="fetch"&gt;'; //echo $result['FIRST_NAME']." ".$result['QUALIFICATION']." ".$result['Specialization']; //echo "&lt;td&gt;&lt;img src='uploads/$row[1].png' height='100px' width='300px'&gt;&lt;/td&gt;"; 这里有问题。您注释掉了其中一些行,但其中一些行下面的行没有被注释掉。
  • 另外,datetimepicker1 id 在哪里?您没有支持该问题的代码。
  • 问问下面那个给你答案的人。我将不得不传递这个问题,祝你好运。

标签: php twitter-bootstrap datepicker bootstrap-datetimepicker


【解决方案1】:

您需要包含documentation 中所述的所有 datetimepicker 依赖项(jQuery、moment.js、bootstrap.js)。您应该在 head 或 html 末尾添加导入代码(在初始化日期选择器之前)。导入示例如下(显然需要配置正确的路径):

<script type="text/javascript" src="jquery.min.js"></script>
<script type="text/javascript" src="moment.min.js"></script>
<script type="text/javascript" src="bootstrap.min.js"></script>
<script type="text/javascript" src="bootstrap-datetimepicker.min.js"></script>

日期时间选择器的 html 位于 while 循环内,因此您需要使用 class 而不是 id。你的 html 应该是这样的:

echo  "<div class='input-group date' class='datetimepicker5'>"

和你的初始化代码:

$(document).ready(function() {
    $('.datetimepicker5').datetimepicker();
});

请注意,您缺少body 标记并且&lt;span class='input-group-addon'&gt; 永远不会关闭。

【讨论】:

    【解决方案2】:

    我注意到您将datetimepicker5 id 添加到 div 中,它应该应用于input type text

    【讨论】:

    • 我有这些链接,伙计。
    • 你的意思是这样-- echo "";
    • 不上课,身份证!您的 jquery 是从 # 中选择的,它是 id 的选择器,如果您想要类,则必须使用点 .
    猜你喜欢
    • 1970-01-01
    • 2017-05-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-08-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多