【问题标题】:Date picker in JQuery and phpJQuery 和 php 中的日期选择器
【发布时间】:2014-04-07 08:49:34
【问题描述】:

我正在使用JQuery 实现日历。这是我测试的 pure html 表单,它运行良好。但是当我将它嵌入到 php 中时,它不起作用并且当我选择检查元素时出现错误是--> 对象没有方法 datepicker。

纯 HTML:

<html lang="en">
<head>
<title>Date Thing</title>
<link href="jquery-ui-1.10.4.custom/css/start/jquery-ui-1.10.4.custom.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="jquery-ui-1.10.4.custom/js/jquery-1.10.2.js"></script>
<script type="text/javascript" src="jquery-ui-1.10.4.custom/js/jquery-ui-1.10.4.custom.js"></script>
<script type="text/javascript" src="jquery-ui-1.10.4.custom/js/jquery-ui-1.10.4.custom.min.js"></script>
<script type="text/javascript">
$(document).ready(function () {

$( "#datepickerID" ).datepicker({
    changeYear: true,
})
});
</script>
</head>
<body>
<p>Date: <input type="text" id="datepickerID"></p>
</body>
</html>

PHP 代码:

 <?php
    include('sess.php');
    ?>
    <!DOCTYPE html>
    <html lang="en">
    <head>
        <title>PAGE TITLE</title>
        <link rel="stylesheet" type="text/css" href="bootstrap.css">
        <link rel="stylesheet" type="text/css" href="bootstrap.theme.css">

        <link href="jquery-ui-1.10.4.custom/css/start/jquery-ui-1.10.4.custom.css" rel="stylesheet" type="text/css"/>

        <script type="text/javascript" src="jquery-ui-1.10.4.custom/js/jquery-1.10.2.js"></script>
        <script type="text/javascript" src="jquery-ui-1.10.4.custom/js/jquery-ui-1.10.4.custom.js"></script>
        <script type="text/javascript" src="jquery-ui-1.10.4.custom/js/jquery-ui-1.10.4.custom.min.js"></script>

        <script type="text/javascript">

        $(document).ready(function () {

        $( "#datepickerID" ).datepicker({
        changeYear: true,
        })

        });
        </script>
</head>
<body>
    <form name="form1" action="http://*****/******/redirect1.php" onsubmit="return validateForm();" method="get">
    <p>Date: <input type="text" id="datepickerID"></p>
    </form>
    </body>
    </html>

有人可以告诉我如何使该日历即使在 php 代码中也能正常工作?

【问题讨论】:

  • 确保js文件没有在整个代码中重复,可能有js代码冲突,你在错误控制台中遇到什么样的错误?
  • 控制台中的任何其他错误。
  • @SagarPanchal 同样的错误--> 对象没有日期选择器方法。如果您可以提供工作示例,请使用 php。
  • @Jai 没有其他错误。除了这个。
  • @rick 检查我的答案

标签: php jquery calendar


【解决方案1】:

这通常意味着您没有加载 JQuery UI 库。但是,看起来您正在加载它两次。也许尝试删除&lt;script type="text/javascript" src="jquery-ui-1.10.4.custom/js/jquery-ui-1.10.4.custom.js"&gt;&lt;/script&gt;。这可能会导致冲突。

【讨论】:

    【解决方案2】:

    请在 ypur PHP 文件中试试这个。

    <?php
        include('sess.php');
    ?>
    <html lang="en">
        <head>
                <title>PAGE TITLE</title>
                <link rel="stylesheet" href="//code.jquery.com/ui/1.10.4/themes/smoothness/jquery-ui.css">
                <script src="//code.jquery.com/jquery-1.9.1.js"></script>
                <script src="//code.jquery.com/ui/1.10.4/jquery-ui.js"></script>
                <link rel="stylesheet" href="/resources/demos/style.css">
                <script type="text/javascript">
                $(document).ready(function () {
                    $( "#datepickerID" ).datepicker({
                        changeYear: true,
                    })
                });
                </script>
        </head>
        <body>
                <form name="form1" action="" onsubmit="return validateForm();" method="get">
                    <p>Date: <input type="text" id="datepickerID"></p>
                </form>
        </body>
    </html>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-09-11
      • 2011-09-29
      • 2011-03-09
      • 2016-09-11
      • 2011-08-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多