-->

Cannot get Jquery DateTimePicker to display in mvc

2020-06-29 02:41发布

问题:

here is my script

<script type="text/javascript">
$(document).ready(function () {
   // alert("jquery working fine, still no display..");
    $(".datepicker").datetimepicker({
        showAnim: 'slideDown',
        dateFormat: 'dd/mm/yyyy'
    });
});
</script>

 <input type="text" class="datepicker" />

The actual Datepicker works great, firebug shows this script, the jqueryUI, the timepicker-addon.js, slider.js, and datepicker.js, jquery is selecting the textboxes.

but alas, still no datetimepicker displaying

I've tried using id's/classes, rearranging the order the scripts are loaded. I would say that the addon is just bunk, but so many seem to have no troubles at all with it. Does anyone know what I am missing?

回答1:

The following code works perfectly fine for me:

<!DOCTYPE html>
<html>
<head>
    <meta name="viewport" content="width=device-width" />
    <title>Index</title>
    <link href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/themes/base/jquery-ui.css" rel="stylesheet" type="text/css" />
</head>
<body>
    <input type="text" class="datepicker" />

    <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
    <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.21/jquery-ui.min.js"></script>
    <script type="text/javascript" src="http://trentrichardson.com/examples/timepicker/jquery-ui-timepicker-addon.js"></script>
    <script type="text/javascript">
        $('.datepicker').datetimepicker({
            showAnim: 'slideDown',
            dateFormat: 'dd/mm/yy'        
        });
    </script>
</body>
</html>

Gives the following result as can be seen in this live demo:

So I guess there must be something wrong with your script inclusions and maybe their order. Unfortunately since you haven't shown your code it is difficult to be able to say more.