failing to cross the pons asinorum with jquery dat

2019-06-11 14:07发布

OK, well, this has got to be something really dumb.

I've got a little JSP app. I want to add a date picker. I downloaded the jQuery UI bundle. If I point chrome at the index.html that it gives me as a demo, all is well. When I move the pieces into my webapp, not so good.

The chrome console shows two things:

  1. Resource interpreted as script but transferred with MIME type text/html.
  2. Uncaught TypeError: Object # has no method 'datepicker'

Obviously, the second is where the headache arrives. I do have a <div id='calendar'>.

<head>
        <link rel="stylesheet" type="text/css" href="/css/harvest.css" />
        <link type="text/css" href="/css/smoothness/jquery-ui-1.8.2.custom.css" rel="stylesheet" />
        <title>Data Collection</title>
        <script type="text/javascript" src="/js/jquery-1.4.2.min.js"></script>
        <script type="text/javascript" src="/js/jquery-ui-1.8.custom.min.js"></script>
        <script type="text/javascript"> 
            $(function(){
                // Datepicker
                $('#calendar').datepicker({
                    inline: true, altField: 'input#date', altFormat: 'yy-mm-dd'
                });
            });
        </script>
    </head>

2条回答
我只想做你的唯一
2楼-- · 2019-06-11 14:20

EDIT: I figured it out. (I'm pretty certain)

you have a script loading from /js/jquery-ui-1.8.custom.min.js, but when I dl a ui bundle, it downloads a file js/jquery-ui-1.8.2.custom.min.js. Notice that the second one has a 2 in it. When I did that, everything worked again for me.

Here are the following basics that I can think of:

  • what happens when you directly go to /js/jquery-1.4.2.min.js and /js/jquery-ui-1.8.custum.min.js ? If those don't work then obviously you have a wrong pathname.
  • have you downloaded a jquery ui package before? perhaps the index.html page you are viewing is not associated with the ui package you dl'ed but with a differently downloaded ui package (which may indicate that you simply forgot to check the datepicker box when dl'ing it this latest time)
  • is there some page that's cached in Chrome? does deleteing all cache help?
  • what happens when you try it in FF, IE, or Safari?
查看更多
倾城 Initia
3楼-- · 2019-06-11 14:33

Another reason for getting this error is when you make the call with the wrong case like this: $("#calendar").date*P*icker() instead of $("#calendar").datepicker()

I have struggled to find this error for a few hours.

查看更多
登录 后发表回答