JQuery datepicker not working

后端 未结 8 1441
遇见更好的自我
遇见更好的自我 2021-02-13 20:27

Good day!

I am trying to use jquery for the first time. And i cannot make it work. My code is as follows:



        
相关标签:
8条回答
  • 2021-02-13 21:10

    The problem is you are not linking to the jQuery UI library (which is where datepicker resides):

    http://jsfiddle.net/5AkyC/

    <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
    <head>
    <link rel="stylesheet" type="text/css" href="style.css" media="screen" />
    <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
    <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.8.9/jquery-ui.js"></script>
    <script>
    $(function() {
        $( "#datepicker" ).datepicker();
    });
    </script>
    </head>
    <body>
        <div class="demo">
        <p>Date: <input type="text" id="datepicker"></p>
        </div><!-- End demo -->
    </body>
    </HTML>
    
    0 讨论(0)
  • 2021-02-13 21:12

    try adjusting the order in which your script runs. Place the script tag below the element it is trying to affect. Or leave it up at the top and wrap it in a $(document).ready() EDIT: and include the right file.

    0 讨论(0)
  • 2021-02-13 21:13

    I was stuck on an issue where datepicker() appeared to be doing nothing. It turned out that the issue was that the input was inside a Bootstrap "input-group" div. Simply taking the input out of the input-group resolved the issue.

    0 讨论(0)
  • 2021-02-13 21:17

    Datepicker is not part of jQuery. You have to get jQuery UI to use the datepicker.

    0 讨论(0)
  • 2021-02-13 21:19

    You did not include the datepicker library

    so add

    <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.8.11/jquery-ui.min.js"></script>
    

    to your <head> tag

    live demo

    0 讨论(0)
  • 2021-02-13 21:26

    after that all html we want to write these lines of code

    <script type="text/javascript" src="http://code.jquery.com/jquery-1.8.2.js"></script>
    <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.8.11/jquery-ui.min.js"></script>
    <link rel="stylesheet" href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.14/themes/base/jquery-ui.css" type="text/css" media="all">
    
    
    
    <script>
    $('#date').datepicker({
        changeMonth: true,
        changeYear: true,
        showButtonPanel: true,
        yearRange: "-100:+0",
        dateFormat: 'dd/mm/yy'
    
    });
    </script>
    
    0 讨论(0)
提交回复
热议问题