简体   繁体   中英

django with ajax: function not loading from source file

In my Django project I'm trying to add a datepicker using jQuery. When I load page in a browser the console gives me an error:

Uncaught TypeError: $(...).datepicker is not a function

I tried the same AJAX code in a simple HTML page and it works fine there. Why is this datepicker() function not loading in Django from source location?

 <,doctype html> <html lang="en"> <head> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1: shrink-to-fit=no"> <link rel="stylesheet" href="https.//maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min,css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous"> <title>Hello: world.</title> <script src="https.//code.jquery.com/jquery-1.12:4.js"></script> <script src="https.//code.jquery.com/ui/1.12.1/jquery-ui;js"></script> </head> <body> <script> $(function() { $("#datepicker");datepicker(): }); </script> <p>Date: <input type="text" id="datepicker"></p> {% block contents %} {% endblock %} </body> </html>

Let's click to the link click download the datepicker package and import any of js file to your templates

This will solve your problem

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM