TypeError:$(...).datepicker不是百里香中的函数 [英] TypeError: $(...).datepicker is not a function in thymeleaf

查看:117
本文介绍了TypeError:$(...).datepicker不是百里香中的函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

jQuery日期选择器不起作用

jQuery date picker is not working

这是我的html

        <!DOCTYPE html>
        <html layout:decorator="layout" xmlns:th="http://www.thymeleaf.org">
        <head>
        <title>Tables | Bootstrap 3.x Admin Theme</title>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
        <meta name="viewport" content="width=device-width, initial-scale=1.0" />

        <script type="text/javascript" src="/js/bootstrap.min.js"></script>
        <script type="text/javascript"
            src="/js/twitter-bootstrap-hover-dropdown.min.js"></script>
        <script type="text/javascript"
            src="/js/bootstrap-admin-theme-change-size.js"></script>

        <script type="text/javascript" src="/js/DT_bootstrap.js"></script>

        <!-- Bootstrap -->
        <link rel="stylesheet" media="screen" href="/css/bootstrap.min.css" />
        <link rel="stylesheet" media="screen"
            href="/css/bootstrap-theme.min.css" />

        <!-- Bootstrap Admin Theme -->
        <link rel="stylesheet" media="screen"
            href="/css/bootstrap-admin-theme.css" />
        <link rel="stylesheet" media="screen"
            href="/css/bootstrap-admin-theme-change-size.css" />

        <!-- Datatables -->
        <link rel="stylesheet" media="screen" href="/css/DT_bootstrap.css" />


        <!-- Jquery -->
        <link rel="stylesheet"
            href="http://code.jquery.com/ui/1.10.2/themes/smoothness/jquery-ui.css" />
        <script src="http://code.jquery.com/jquery-1.9.1.js"></script>
        <script src="http://code.jquery.com/ui/1.10.2/jquery-ui.js"></script>


        <script type="text/javascript">
            function notify() {
                alert("Notify called");
                $("#datepicker").datepicker();
            }
            $(function() {
                alert("hi");
                $("#datepicker").datepicker();
            });
        </script>
       </head>


           <body>
           <div>
            <input type="text" id="datepicker" name="endDate"
                                    onkeyup="notify()" />
            </div>
            </body>

我尝试了几种解决方案,这些解决方案都在stackoverflow中,但是它们都不起作用...

I tried several solutions, which are there in stackoverflow, but none of them are working...

由于百里香,我是否需要以其他方式使用jquery?

do I need to use jquery in another way because of thymeleaf?

请帮帮我...

推荐答案

请参见

See the Thymeleaf documentation about inline javascript. You should use the following (best at the end of the page before </body>). From what I recall wrapping the javascript in /*<![CDATA[*/ and /*]]>*/ is required.

<script th:inline="javascript">
    /*<![CDATA[*/

    $(function () {
        $("#datepicker").datepicker();
    });

    /*]]>*/
</script>

这篇关于TypeError:$(...).datepicker不是百里香中的函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆