django和jquery ui datepicker无法正常工作

时间:2014-02-10 01:20:14

标签: jquery django jquery-ui datepicker django-forms

当我使用基本的html测试时,我的datepicker有效,但是当我将它添加到django时,它就停止工作了。是我还是django和jquery datepicker不能一起工作?有人知道在django中添加datepicker和timepicker的更简单方法吗?

的ModelForm

class AuthorForm(forms.ModelForm):

    class Meta:
        model = Author
        fields = ['date','email',]
        widgets = {
            'date': DateInput(attrs={'class': 'datepicker'}),
            'email': EmailInput(attrs={'class': 'form-control'}),
        }

authorcreate.html

          {% load account %}
            <!doctype html>
            <html lang="us">
            <head>
                <meta charset="utf-8">
                <title>jQuery UI Example Page</title>
                            <style>
                div.ui-datepicker{
             font-size:8px;
            }
                </style>
                <script src="static/test/js/vendor/modernizr-2.6.2-respond-1.1.0.min.js"></script>
                <script type="text/javascript" src="static/test/js/jquery-1.10.2.js"></script>
                    <script type="text/javascript" src="static/test/js/jquery-ui-1.10.4.custom.js"></script>
                    <script type="text/javascript" src="static/test/js/bootstrap.js"></script>
                    <link type="text/css" href="static/test/css/cupertino/jquery-ui-1.10.4.custom.css" rel="stylesheet" />

   <script>
$(function() {

    if (!Modernizr.inputtypes.date) {

        $( ".datepicker" ).datepicker({
            inline: true
        });
        // Hover states on the static widgets
        $( ".#dialog-link, #icons li" ).hover(
            function() {
                $( this ).addClass( "ui-state-hover" );
            },
            function() {
                $( this ).removeClass( "ui-state-hover" );
            }
        );

    }
});
    </script>
    </head>
    <body>
            Create a contact form
            <form method="post">{% csrf_token %}
                {{ form.as_p }}
                <input type="submit" value="Submit" />
            </form>

            </body>
            </html>

0 个答案:

没有答案